Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] weak type variables in module type declarations
Tyng-Ruey Chuang <trc@iis.sinica.edu.tw> 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
> http://www.ocaml.org/bin/caml-bugs/not%20a%20bug?expression=weak;user=guest
> 
> 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 =
struct 
  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));;
end

which have as type:

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

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
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr