Hi,

I have an implementation of the Y which crashes Poly/ML. Take the program below 
and evaluate "fact n" with n>3.

I've tried it on both x86 and SPARC Solaris systems with Poly/ML 5.3, as well 
as on a (x86) MacOSX system with Poly/ML 5.4.1.

The program works in both Moscow ML and SMLNJ, so I'm pretty sure it is correct 
SML.

Best regards,

Lars-Henrik Eriksson, PhD, Senior Lecturer
Computing Science, Dept. of Information Technology, Uppsala University, Sweden
E-mail: [email protected], Web: http://www.it.uu.se/katalog/lhe?lang=en
Phone: +46 18 471 10 57, Mobile: +46 705-36 39 16, Fax: +46 18 51 19 25

--------

(* The Y combinator in ML *)

abstype 'a ft = FT of 'a ft -> 'a
with
 val Y = fn f => (fn (FT x) => (f (fn a => x (FT x) a)))
                 (FT (fn (FT x) => (f (fn a => x (FT x) a))))
end

(* Y is the fixed point operator, i.e. fix F = Y(F) *)
(* Y has type (('a -> 'b) -> ('a -> 'b)) -> ('a -> 'b) *)

(* Recursive definitions such as
  val rec f = ...    can be written
  val f = Y (fn f => ...)   *)

fun Fact f n = if n = 0 then 1 else n * f(n-1)

val fact = Y Fact
_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

Reply via email to