Browse thread
[Caml-list] Is a Cow an Animal?
[
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: | -- (:) |
| From: | james woodyatt <jhw@w...> |
| Subject: | Re: [Caml-list] Is a Cow an Animal? |
On Thursday, April 18, 2002, at 03:44 PM, Pixel wrote: > > well, i don't really understand the """type 'diet energy = int""" stuff. > but neither is my ocaml's: > > # let carrot = new carrot 2 ;; > # let cow = new cow 10 ;; > # let _ = cow#feed carrot#energy ;; > > # cow#feed;; > - : [ `E_cow] energy -> cow = <fun> > # carrot#energy;; > - : [ `E_rabbit | `E_human] energy = 2 > # (carrot#energy : [ `E_cow ] energy);; > - : [ `E_cow] energy = 2 > > what am i missing? It looks like the 'a energy type is not actually abstract in your trial above. It has to be abstract or the technique doesn't work. # carrot#energy;; - : [ `E_rabbit | `E_human] energy = 2 Since the type is concrete, it resolves at compile time into an integer, and an integer is an integer is an integer. Try compiling the .cmo file from the .ml and .mli files I posted and using the #load directive from the top-level. -- j h woodyatt <jhw@wetware.com> ------------------- 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