Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] simple typing question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-03 (01:50)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] simple typing question
From: Pixel <>
> Pierre Weis <> writes:
> > > what about changing the semantic of partial application, restoring
> > > eta-equivalence: a function is not evaluated unless every arguments
> > > are given:
> > 
> > Could you precisely state this notion ? In the presence of higher
> > order functions and imperative features, this does not appear to be
> > simple and evident to me...
> well, wrap every functions:
> # let make_toggle_ () =
>     let r = ref [] in fun x -> let old = !r in r := x; old
> with
> # let make_toggle a b = make_toggle_ a b
> based on the number of parameters of functions (given by the type).
> This disables evaluation of a function until every parameters are
> provided.

Let's make it a bit clearer: what you're asking for is that everything
with a function type should be a value.
This is not completely unreasonable, but changes the semantics in a
not completely intuitive way, and would disallow some nice tricks.
Not completely trivial to implement either: as Pierre pointed out,
some functions returning a polymorphic result have by nature a
variable arity.  One should rewrap every time the arity changes, which
could be costly.

Another problem is that it is asymmetric: partial applications could
be polymorphic, but not results containing several functions:

let both f = ( f, List.iter f)

> The program transformation involved is something like:
>   let t = foo in fun x -> bar
> gives
>   fun x -> let t = foo in bar

This one is actually used for default values in optional parameters,
to make them more efficient (hence there should be no side-effects in
Note that this rule alone would not be enough to do the needed

let toggle r x = let old = !r in r := x; old
let make_toggle () = let r = ref [] in toggle r

You really have to look at the type, which is not very clean.
(Currently the semantics of Caml is completely independent of inferred

So, this seems unlikely such changes would go through.

Without changing the semantics, there are ways to refine the current
typing, but you cannot allow (fun x -> x) to be polymorphic
without giving a special typing to mutable values or side effects
(which has been shown to be a pain in ML).

Jacques Garrigue
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: