caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* generalization in tuples
@ 2000-10-16 12:42 David Monniaux
  2000-10-17  8:11 ` Didier Remy
  0 siblings, 1 reply; 3+ messages in thread
From: David Monniaux @ 2000-10-16 12:42 UTC (permalink / raw)
  To: Liste CAML

(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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-10-18  8:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-16 12:42 generalization in tuples David Monniaux
2000-10-17  8:11 ` Didier Remy
2000-10-17 19:17   ` Didier Remy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).