Version française
Home     About     Download     Resources     Contact us    
Browse thread
Type_of?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Zheng Li <li@p...>
Subject: Re: Type_of?

Hello, 

Dario Teixeira <darioteixeira@yahoo.com> writes:
> Now, this works fine.  It is however error prone, since if the signature
> of make_doc changes somewhat and I forget to update the type annotation in
> unpickle_doc, then I get a nasty runtime segfault.  So this is my question:
> since the return type of make_doc is known at compile-time, is there any
> way I can tell the compiler that the return type of unpickle_doc should be
> the same as make_doc's?

Do you have any restriction in bounding them as pairs? The simplest
example come into my mind is like:

# let produce () :'a = [`Zero; `One 1] and consume (l:'a) = ();;
val produce : unit -> [> `One of int | `Zero ] list = <fun>
val consume : [> `One of int | `Zero ] list -> unit = <fun>

In this way, you don't have to write the variants manually, since
"ocamlc -i" can inference it and the type 'a in the pairs are always
bounded.

HTH.
-- 
Zheng Li
http://www.pps.jussieu.fr/~li