Version française
Home     About     Download     Resources     Contact us    
Browse thread
How do I get polymorphic partial application?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Philippe Wang <lists@p...>
Subject: Re: [Caml-list] How do I get polymorphic partial application?
Lukasz Stafiniak wrote:
> On 6/23/07, Philippe Wang <lists@philippewang.info> wrote:
>> Till Varoquaux wrote:
>> > Humm... I have a small issue here: I need to get the result of the
>> > partial application of a polymorphic function. Since variable are
>> > generalized in Let it is generally advised to use eta expansions,
>> > (i.e transform to a total application).
>> > sometimes eta expansions just won't do the trick, consider:
>>
>> I think you should not try to "hide" that ugly side effect...
>>
> Could someone give an example where this "eta-thing" forbids a crash?
> I don't remember any example even in Xavier Leroy papers.

If I understand what you mean, this could explain it :

let foo () =
   let container = ref [] in
     fun x -> container := x :: !container; !container

val foo : unit -> 'a -> 'a list

(* first : doesn't work *)
let plop = foo ()
let l1 = plop 42
let l2 = plop "42"  (* crash  -- but wouldn't crash with most *dynamic* 
typing systems *)

let plop2 = fun () -> foo ()
let l1' = plop2 () 42
let l2' = plop2 () "42"  (* no crash *)

but plop and plop2 don't share the same semantics...

--
  Philippe Wang
    mail[at]philippewang.info