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] weak type variables in module type declarations
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-05-23 (13:57)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] weak type variables in module type declarations
Tyng-Ruey Chuang <> writes:

> Dear all,
> O'caml compiler does not seem to recognize user-specified 
> weak type variables. The compiler, however, will automatically
> produce weak type variables when they are needed.
> This behavior has been observed and reported as "Id 246"
> in the "Known bugs" list (and classified as "not a bug"). See
> What do you do to get around this? In my case, the week type variables
> are indeed useful, and I want to keep them. But since I have no way
> in putting weak type variables in module type declarations, I am prevented
> to program in a modular way. Consider the following code segment:
> 	let ($) f g x = f (g x)   (* functional composition *)
> 	let id x = x              (* the identity function  *)
> 	module Sum =
> 	struct
> 	  type ('a, 'b) t = Pink of 'a | Blue of 'b
> 	  let pair = (id $ (fun a -> Pink a), id $ (fun b -> Pink b))
> 	end

i really don't believe you want weak type here : weak type are that
will be determine latter :
if you make a 
Sum.pair 1 2
then after this, Sum.pair will have the mostly monomorphic type 
    val pair : (int -> (int, '_b) t) * (int -> (int, '_d) t)

you may have something very similar, but without weaktype, thanks to
an eta-transformation :

module Sum =
  type ('a, 'b) t = Pink of 'a | Blue of 'b
  let pair = ((fun x -> (id $ (fun a -> Pink a)) x),(fun x -> (id $ (fun b -> Pink b)) x));;

which have as type:

module Sum :
    type ('a, 'b) t = Pink of 'a | Blue of 'b
    val pair : ('a -> ('a, 'b) t) * ('c -> ('c, 'd) t)

Which is probably what you want.

The problem with weak type is mostly a FAQ, you should read the FAQ
at this subject
Rémi Vanicat
To unsubscribe, mail  Archives: