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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Goswin von Brederlow <goswin-v-b@w...>
Subject: Re: [Caml-list] Subtyping
Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> writes:

> type 'a base = {x : 'a; fn : 'a -> unit}
> type 'b base_op = {bop: 'a. 'a base -> 'b}
> type base_wrapper = {base: 'b. 'b base_op -> 'b}
>
> let l =
>   let a = {x = 1; fn = print_int}
>   and b = {x = 1.2; fn = print_float} in
>   [{base = fun x -> x.bop a}; {base = fun x -> x.bop b}]
>
> List.iter (fun w -> w.base {bop = fun r -> r.fn r.x}) l
>
> As you can see, the result is rather verbose, but this works.
> Fortunately, closure and objects are usually enough...
>
> Jacques Garrigue

That is exactly what I ment. I knew closures could have "'a. ..."
types but I didn't think of encoding the record and the method to
call both as closures.

MfG
        Goswin