Version française
Home     About     Download     Resources     Contact us    
Browse thread
generalization in tuples
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Monniaux <David.Monniaux@e...>
Subject: generalization in tuples
(En français: pourquoi ne pas généraliser le type d'un tuple pour cause de
non-généralisabilité d'une des parties du tuple si de toute façon les
variables de type à généraliser n'y interviennent pas?)

Some typing problem has been bothering me for the week-end.

Let us consider the following code:
# let extractor f = f ~foo:"aaa" ~bar:"bbb";;
val extractor : (foo:string -> bar:string -> 'a) -> 'a = <fun>
# let grostruc = List.map string_of_int [1; 2; 3];;
val grostruc : string list = ["1"; "2"; "3"]
# let zoinx = grostruc, extractor;;
val zoinx : string list * ((foo:string -> bar:string -> 'a) -> 'a) =
  ["1"; "2"; "3"], <fun>

Very logical, and what I wanted: a tuple with some big computed stuff in
the first member and a polymorphic function in the second (this is of
course a simplified example of the actual production code).

Now I do not want to pollute my namespace defining extractor and grostruc,
since all I'm interested in is zoinx.

# let bidule = let extractor f = f ~foo:"aaa" ~bar:"bbb" and grostruc =
List.map string_of_int [1; 2; 3] in grostruc,extractor;;
val bidule : string list * ((foo:string -> bar:string -> '_a) -> '_a) =

The function application in the definition of grostruc prevents 'a from
being generalized. This code is nevertheless equivalent to the precedent
one except from the namespace pollution.

So I actually have two questions:

1/ Is it possible to do what I want to do, even if it means using a
kludge? The above code, using multiple let's, is not good: it's not
useable in the middle of an expression (this is for CamlP4-generated
code).

(acceptable kludges include the use of Obj.magic)

2/ Is there a finer notion of a "generalizable" expression that
encompasses the above code, and could the "let generalization" procedure
in the compiler be improved so that the above code gets a polymorphic
type?

David Monniaux            http://www.di.ens.fr/~monniaux
Laboratoire d'informatique de l'École Normale Supérieure,
Paris, France