Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] ocaml killer
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andreas Rossberg <rossberg@p...>
Subject: Re: fancy types (was Re: [Caml-list] ocaml killer)
Thomas Fischbacher wrote:
> 
> Look here:
> 
> # let fac n = let do_rec specialist n = if n = 0 then 1 else n * specialist specialist (n-1) in do_rec do_rec n;;
> 
> Characters 74-84:
>   let fac n = let do_rec specialist n = if n = 0 then 1 else n * 
> specialist specialist (n-1) in do_rec do_rec n;;
>                                                                             
> ^^^^^^^^^^
> This expression has type 'a -> 'b -> 'c but is here used with type 'a
> 
> # let fac n = let do_rec specialist n = if n = 0 then 1 else n * (Obj.magic specialist) specialist (n-1) in do_rec do_rec n;;
> val fac : int -> int = <fun>
> 
> # fac 8;;
> - : int = 40320
> 
> This is just one stupid example where the type system gets in the way 
> while it should not.

This is almost an FAQ. Try "ocaml -rectypes".

Note that there are very good reasons for this being an option, since it 
is almost never practically useful, but can lead to "false negatives" 
(code getting accepted although it is plain nonsense) quite easily.

Also note that you can encode most of these examples without -rectypes, 
using variant types.

>>(which already exists in the standard library, it being
>>mysteriously named Obj.magic and its use being highly discouraged).
> 
> For good. I bet this feature exists precisely to keep the LISP wizards 
> happy who know about and are not afraid of these dark corners, and have 
> (maybe out of stubbornness :-) ) a strong desire writing LISP code in 
> ocaml.

No, it is rather there for hacking C bindings and stuff.

> BTW: I also strongly assume that internally, ocaml uses type tagging 
> anyway, at least for the garbage collector; hence it may be possible to 
> use just the engine of ocaml and build a dynamically typed lisp on top of 
> it...?

No, it uses only 1-bit tags.

	- Andreas

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids; I mean if Pac Man affected us
  as kids, we would all be running around in darkened rooms, munching
  magic pills, and listening to repetitive electronic music."
  - Kristian Wilson, Nintendo Inc.

-------------------
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