Version française
Home     About     Download     Resources     Contact us    
Browse thread
Question on polymorphic typing for curried functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christopher Kauffman <kauffman@c...>
Subject: Question on polymorphic typing for curried functions
I am looking for a bit of information on the behavior of curried functions wrt 
polymorphic arguments. For instance, in the following example, using a curried 
function seems to lose the nice polymorphism that I desire.

# let genf f a b = f a b;;
val genf : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = <fun>
# let specf = genf (<);;
val specf : '_a -> '_a -> bool = <fun>
# specf 1 2;;
- : bool = true
# specf;;
- : int -> int -> bool = <fun>

An alternative definition for the specific 'specf' maintains polymorphism of its 
arguments.

# let specf a b = genf (<) a b;;
val specf : 'a -> 'a -> bool = <fun>
# specf 1 2;;
- : bool = true
# specf 1.0 2.0;;
- : bool = true
# specf;;
- : 'a -> 'a -> bool = <fun>

Is there a set of rules or guidelines that determine when argument types are 
specialized versus staying polymorphic?

Cheers,
Chris