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 (18:31)
From: Nathaniel Gray <n8gray@g...>
Subject: Labels and polymorphism
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:

# let f ~x = x;;
val f : x:'a -> 'a = <fun>
# f ~x:1;;
- : int = 1
# f 1;;
- : x:(int -> 'a) -> 'a = <fun>
# let y = f 1;;
val y : x:(int -> 'a) -> 'a = <fun>
# y (fun x -> x+1);;
- : x:(int -> (int -> int) -> 'a) -> 'a = <fun>

Can somebody make sense of this for me?  Is there a paper somewhere on
labels in ocaml that I should read?


>>>-- Nathaniel Gray -- Caltech Computer Science ------>
>>>-- Mojave Project -- http://mojave.cs.caltech.edu -->