Version française
Home     About     Download     Resources     Contact us    
Browse thread
How to do this properly with OCaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: brogoff <brogoff@s...>
Subject: Re: [Caml-list] "Just say no!" campaign against Obj [was: How to do this properly with OCaml?]
On Sun, 24 Jul 2005, Alex Baretta wrote:
> Once upon a time I felt a desperate need for polymorphic recursion. At
> that time the INRIA gang was selling a new ligth drug whose effects are
> similar to polymorphic recursion. They called it "polymorphic records".
> Polymorphic records do not give addiction--unlike polymorphic variants,
> which are much more dangerous from this point of view--but when they are
> used to attain that euphoric state of mind given by polymorphic
> recursion, they must be injected in one's code with Obj.magic. Yes, i
> picked up the syringe and used it. Yes, I got ill with type-unsafety,
> but eventually careful medication made me recover. At the end, I must
> say experiencing polymorphic recursion was well worth the pain that came
> from using Obj.magic.

I was able to use the higher order polymorphism of record fields to implement
polymorphic recursion, WITHOUT using Obj.magic. I posted that approach on the
list a long time ago, it was really the same trick as using polymorphic methods
to do the same. You can use that trick to implement the signatures in Okasaki's
book that use P.R. fairly easily. Why did you need Obj.magic?

Recursive modules provide a nicer approach, IMO, and explicit types even nicer.

> Notwithstanding my experience, I agree with Xavier that is the social
> duty of us all to discourage the young generations to take Obj as a
> means to escape the conventional type system imposed upon them by
> society.

My issues with the type system are rarely (if ever) made better by using
Obj.magic. GCaml and Alice (with it's packages) tackle the main issue,
which is type safe marshalling.

I agree that a more expressive type system would be nice, and I used Obj
too to get a set_cdr thing going (like in ExtLib) but if you need efficiency
that badly then I think it makes more sense to use C and extend OCaml that
way.

-- Brian