Gerd Stolpmann a écrit :
Am Dienstag, den 09.02.2010, 22:58 +0100 schrieb Guillaume Yziquel:
Gerd Stolpmann a écrit :
Am Dienstag, den 09.02.2010, 15:50 -0500 schrieb Saptarshi Guha:
Besides the different way of defining "let" and "let rec" there are also
differences in typing.
Well, at least you can have new effects. Look for "polymorphic
recursion".
You mean something like this?
http://alaska-kamtchatka.blogspot.com/2009/05/polymorphic-recursion.html
With the following code
type length = { length : 'a . int -> 'a vec -> int }
let length v =
let rec f = { length = fun n l -> match l with
Nil -> n
| Zero ps -> f.length ( 2 * n) ps
| One (_, ps) -> f.length (1 + 2 * n) ps
} in f.length 0 v
you get to use a function, here f.length, in two different contexts for
type inference, allowing it to be used with multiple types? 'a * 'a
instead of 'a? Am I getting this post right?
But then, this seems to go into rather elaborate constructions
(existential types with OCaml records), which are quite remote from the
simple 'let rec' issue we were talking about.
Is it possible to have polymorphic recursion with vanilla 'let rec'
invocations? Or am I getting you wrong?
All the best,
--
Guillaume Yziquel
http://yziquel.homelinux.org/
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs