Browse thread
[Caml-list] Compiler killer code?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2002-06-08 (18:30) |
From: | William Lovas <wlovas@s...> |
Subject: | Re: [Caml-list] Compiler killer code? |
On Sat, Jun 08, 2002 at 07:34:02AM -0700, William Lee Irwin III wrote: > > Is the type inference algorithm guaranteed to termintate? I > > ask because I have accidentally attempted to evaluate a > > (meaningless) function which almost hanged my Athlon. > > The killer code is the following: > > type t = t -> t > > let f (x:t) :t = f f > > If I type this into the toplevel, it starts to allocate > > memory by the tens of megabytes, until I have to kill it to > > prevent a system crash. I let it reach approximately 128MB > > before killing it. (BTW, that was with ocaml 3.04+13 > > 2002-06-05.) > > Is the language really supposed to accept such garbage as > > that which I wrote? I wonder if it really would have crashed your system, or if O'Caml would have simply died with an `out of memory' error. > On Sat, Jun 08, 2002 at 04:32:13PM +0200, Alessandro Baretta wrote: > > I get this instead: > > # type t = t -> t;; > The type abbreviation t is cyclic If you use recursive types (`ocaml -rectypes'), it typechecks fine: # type t = t -> t;; type t = t -> t # let rec f (x : t) : t = f f;; val f : t = <fun> In fact, you don't even need to define the type abbreviation: # let rec f x = f f;; val f : 'a -> 'b as 'a = <fun> This is O'Caml 3.04 -- if it fails to typecheck in the CVS version, then i'd say either the semantics of recursive types have changed or a bug has been introduced. cheers, William ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners