Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] simple typing question
From: Pixel <pixel@mandrakesoft.com>
> Pierre Weis <pierre.weis@inria.fr> 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 = (List.map 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
defaults).
Note that this rule alone would not be enough to do the needed
transformation:

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
types)

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 List.map (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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners