English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Labels and polymorphism
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-03-08 (23:30)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Labels and polymorphism
On Thu, 2007-03-08 at 10:31 -0800, Nathaniel Gray wrote:
> I was recently bemoaning the way that folds (especially nested folds)
> using longish anonymous functions become very hard to read, since the
> argument order is optimized for greatest opportunity for partial
> application rather than readability.  This led me to think about using
> ListLabels in my code, but then I hit this bit of documentation:
> """
> As an exception to the above parameter matching rules, if an
> application is total, labels may be omitted. In practice, most
> applications are total, so that labels can be omitted in applications.
> ...
> But beware that functions like ListLabels.fold_left whose result type
> is a type variable will never be considered as totally applied.
> """
> Wha??  I'm trying to wrap my head around this but I'm just totally
> confused.  I thought that playing around in the interpreter would
> help, but it just left me more confused:

It's simple:

# let id x = x;;
val id : 'a -> 'a = <fun>
# id 1;;
- : int = 1

id has arity 1 and is fully applied when it has one argument

# let f x = x * x;;
val f : int -> int = <fun>

# id f 2;;
- : int = 4

WOOPS! Here id has TWO arguments ...

So the arity of a function returning a type variable is
indeterminate, so you cannot tell if it is fully applied or not.

Hence the caveat.

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net