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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alessandro Baretta <a.baretta@b...>
Subject: Re: [Caml-list] function specialization
Vsevolod Fedorov wrote:
> Hello!
> 
> I have code like following:
> ----
> 
> type 'a wrap = ('a -> unit) -> 'a -> unit

type wrap = { action : 'a. ('a -> unit) -> 'a -> unit }

> let wrap fn arg =
>   fn arg

let wrap = { action = fun fn arg -> fn arg }

> let fn1 (v: int)    = ()
> let fn2 (v: string) = ()
> 
> let use (wrap: 'a wrap) =
>   wrap fn1 1;
>   wrap fn2 ""
>   (*   ^^^ This expression has type string -> unit but is here used with
> type int -> unit *)

let use (wrap : wrap) =
   wrap.action fn1 1;
   wrap.action fn2 ""

Alex