Browse thread
[Caml-list] weak type variables in module type declarations
- Tyng-Ruey Chuang
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Tyng-Ruey Chuang <trc@i...> |
| Subject: | [Caml-list] weak type variables in module type declarations |
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