Browse thread
Variance problem in higher-order Functors?
-
Jacques Carette
-
Andreas Rossberg
- Jacques Carette
-
Andreas Rossberg
[
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: | 2006-07-25 (20:45) |
From: | Jacques Carette <carette@m...> |
Subject: | How do I achiece this, was Re: [Caml-list] Variance problem in higher-order Functors? |
My real question is (and should have been), how do I translate module type DOMAIN = sig type kind end type domain_is_field type domain_is_ring module Rational = struct type kind = domain_is_field end module Integer = struct type kind = domain_is_ring end module DivisionUpdate(D:DOMAIN with type kind = domain_is_field) = struct (* something only valid with D a field*) end module GeneralUpdate(D:DOMAIN) = struct (* something that always works, for rings and fields *) end The behaviour I want should be the same as the first-order applications module A = DivisionUpdate(Rational) (* OK *) module B = GeneralUpdate(Rational) (* OK *) module C = DivisionUpdate(Integer) (* ERROR *) module D = GeneralUpdate(Integer) (* OK *) BUT I want to pass all these modules as parameters to a functor. I don't see how to build the proper type that will work! [I have read the manuals in depth, Googled around the caml.inria.fr web site, played around with the implementation, etc to no avail] In other words, I want to be able to define module type Trans = functor(U:UPDATE) -> functor(D:DOMAIN) -> sig ... end but none of my attempts have worked, even though the first-order code works fine. I would be happy with a solution that uses polymorphic variants, or objects, or whatever work. The only thing I can't do is "run-time" tests, as I have a dozen domains, with more functors and more constraints floating around, so I really want this to be a type-level solution. If OCaml had conditional module application, I could use that, but "expanding" my definitions is not realistic. Jacques