* [Caml-list] type and modules... (sig mismatch again)
@ 2003-06-18 10:41 Pietro Abate
2003-06-18 11:07 ` Damien Pous
2003-06-18 11:09 ` Andreas Rossberg
0 siblings, 2 replies; 3+ messages in thread
From: Pietro Abate @ 2003-06-18 10:41 UTC (permalink / raw)
To: caml-list
Hi all,
my daily question :-))
I would like to write a module definition as below:
the problem is (of course) with the t1_t and t2_t type definition because the
use the same variant names. however in my understanding the signature + the "(A
with type t1 = t1_t and type t2 = t2_t)" bit in the functor declaration should
be enough to make clear to the compiler that tutu gets t1 and return t2. Hence
in the pattern matching the first A is of the type t1 and the B is of type t2.
how can I force this behavior without changing t1_t and t2_t ?
why the signature doesn't enforce the right type matching ?
regards,
pietro
module type A = sig
type t1
type t2
val tutu : t1 -> t2
end
type t1_t = A of int
type t2_t = A of int | B of int
module Make : (A with type t1 = t1_t and type t2 = t2_t) = struct
type t1 = t1_t
type t2 = t2_t
let tutu = function
|A(x) -> B(x)
end
--
Civilization advances by extending the number
of important operations which we can perform
without thinking. (Alfred North Whitehead)
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] type and modules... (sig mismatch again)
2003-06-18 10:41 [Caml-list] type and modules... (sig mismatch again) Pietro Abate
@ 2003-06-18 11:07 ` Damien Pous
2003-06-18 11:09 ` Andreas Rossberg
1 sibling, 0 replies; 3+ messages in thread
From: Damien Pous @ 2003-06-18 11:07 UTC (permalink / raw)
To: caml-list
Le mer 18/06/2003 à 12:41, Pietro Abate a écrit :
> my daily question :-))
my daily answer !
maybe I'm wrong (if so, please correct me) but I believe the module
is built and its signature is inferred, and then this signature is
matched against the one you provide (A with ...)
so the signature you provide isn't used to infer the types...
furthermore the hidden type constructor A for t1_t is "hidden for ever",
that is, you can't use it even under type constraint :
'(A 5 : t1_t)' should not be accepted
I don't know what you plan to do with this, but maybe you should look at the
polymorphic variants :
type t1 = [`A]
type t2 = [t1 | `B]
...
Cheers,
damien
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] type and modules... (sig mismatch again)
2003-06-18 10:41 [Caml-list] type and modules... (sig mismatch again) Pietro Abate
2003-06-18 11:07 ` Damien Pous
@ 2003-06-18 11:09 ` Andreas Rossberg
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Rossberg @ 2003-06-18 11:09 UTC (permalink / raw)
To: caml-list
Pietro Abate wrote:
>
> how can I force this behavior without changing t1_t and t2_t ?
You can wrap them in auxiliary modules. One purpose of modules is name
space management.
> why the signature doesn't enforce the right type matching ?
Due to the way data type declarations work, this is not a typing issue,
but purely a scoping issue. The first constructor A is simply shadowed
by the second one, so A always refers to the latter.
Beside that, modules are typed independently of any signature
constraint. The latter is checked only after typing the module body.
This is an important design principle of the module language. So even if
both A's could be disambiguated by typing in some way, the information
provided by the signature would come "too late".
- Andreas
> module type A = sig
> type t1
> type t2
> val tutu : t1 -> t2
> end
>
> type t1_t = A of int
> type t2_t = A of int | B of int
>
> module Make : (A with type t1 = t1_t and type t2 = t2_t) = struct
> type t1 = t1_t
> type t2 = t2_t
> let tutu = function
> |A(x) -> B(x)
> end
--
Andreas Rossberg, rossberg@ps.uni-sb.de
"Computer games don't affect kids; I mean if Pac Man affected us
as kids, we would all be running around in darkened rooms, munching
magic pills, and listening to repetitive electronic music."
- Kristian Wilson, Nintendo Inc.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-06-18 11:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-18 10:41 [Caml-list] type and modules... (sig mismatch again) Pietro Abate
2003-06-18 11:07 ` Damien Pous
2003-06-18 11:09 ` Andreas Rossberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox