caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Tyng-Ruey Chuang <trc@iis.sinica.edu.tw>
To: caml-list@inria.fr
Cc: trc@iiserv.iis.sinica.edu.tw
Subject: [Caml-list] weak type variables in module type declarations
Date: Wed, 23 May 2001 21:24:42 +0800 (CST)	[thread overview]
Message-ID: <200105231324.f4NDOgc28482@mail.iis.sinica.edu.tw> (raw)

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

	module type SUM =
	sig
	  type ('a, 'b) t = Pink of 'a | Blue of 'b

	  val pair : ('_a -> ('_a, '_b) t) * ('_a -> ('_a, '_b) t)
	end


The compiler report module type SUM as

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

which is different from my specification. Therefore, I cannot write
code like

	module Empty = functor (S: SUM) -> struct  end
	module E = Empty(Sum)

because the last line produces a "signature dismatch" error from
the compiler.

Of course, the dismatch goes away if the code for module Sum is changed to

        module Sum =
        struct
          type ('a, 'b) t = Pink of 'a | Blue of 'b
          let pair = ((fun a -> Pink a), (fun b -> Pink b))
        end                                                                    

because the week type variables now disappear. However, this is not what
I want. I program mostly in equational style. The function "id"
in the original definition of module Sum in fact is a complex function
that better to be left alone. I also need the two occurrences 
of the weak type variable '_a to resolve to the same type.

The usual Obj.magic trick to coerce the compiler to accept unsafe
value definition does not work either, as it cannot eliminate 
weak types.

I will appreciate any thought on how to deal with this situation.

Last, but not least, many thanks to the Caml team for
the fine language and compiler.

Tyng-Ruey Chuang
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-23 13:24 Tyng-Ruey Chuang [this message]
2001-05-23 13:57 ` Remi VANICAT
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=200105231324.f4NDOgc28482@mail.iis.sinica.edu.tw \
    --to=trc@iis.sinica.edu.tw \
    --cc=caml-list@inria.fr \
    --cc=trc@iiserv.iis.sinica.edu.tw \
    /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).