[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: in defense of types




matthias@ccs.neu.edu writes:
> > 
> > # let rec l = 1 :: l in l;;
> > - : int list =
> > [1; 1; 1; 1; 1; 1; 1; ....
> > 
> > This is nice, but not very useful, since recursive data structures
> > typically need more complicated initialization, and then you can't
> > use the letrec structure and have to resort to mutable data.
> 
> Bruce Duba and I experimented with this extension in the early 90s.
> We design and implemented a prototype and had an undergraduate (I
> think Steve Weeks) scale it to all of Chez Scheme at the time. The
> experiment showed that the slow-down was high and the usefulness
> limited.

I've used this extension in only one situation. When writing a lambda
calculus interpreter, it's cool to be able to evaluate recursive
functions with an expression like:

let eval expr env = 
  match expr with
  [...]
  | Rec(name, arg, body) ->
     let rec env' = (name, closure) :: env 
     and closure = Closure(env', arg, body)
     in
     closure

This idiom doesn't scale to mutual recursion, though.

-- 
Neel Krishnaswami
neelk@alum.mit.edu