caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Remi VANICAT <vanicat@labri.u-bordeaux.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] weak type variables in module type declarations
Date: 23 May 2001 15:57:55 +0200	[thread overview]
Message-ID: <ya3heycyxp8.dlv@serveur3-1.labri.u-bordeaux.fr> (raw)
In-Reply-To: <200105231324.f4NDOgc28482@mail.iis.sinica.edu.tw>

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


  reply	other threads:[~2001-05-23 13:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-23 13:24 Tyng-Ruey Chuang
2001-05-23 13:57 ` Remi VANICAT [this message]
2001-05-28  8:03 ` Francois Pottier
2001-05-28 12:50 ` Xavier Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ya3heycyxp8.dlv@serveur3-1.labri.u-bordeaux.fr \
    --to=vanicat@labri.u-bordeaux.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).