Re: Use "with type" with functorial signatures
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAPFanBH5N5qOtwoeK4hGVCyG1FLsuSx0b=cU0KSsXbVa=ZD+pQ@mail.gmail.com> |
You can express this with a functor returning the signature. You'll
have to provide an implementation for the functor in the corresponding
.ml (if there is a .ml), but it is trivial.
module type BAR = sig
type t
end
module FooS : functor (Bar:BAR) -> sig
module type Sig = sig
type u
type t = Bar.t
end
end
module type Foo = functor (Bar:BAR) -> FooS(Bar).Sig
module Make : functor (Bar:BAR) -> (FooS(Bar).Sig with type u = string)
On Mon, Jun 2, 2014 at 4:57 PM, Philippe Veber
[email protected] [ocaml_beginners]
<[email protected]> wrote:
>
>
> Hi Chantal,
>
> Not sure you can have what you want, in particular I expected the following
> to work
>
> module type BAR = sig
> type t
> end
>
> module type FOO = functor (Bar:BAR) -> sig
> type u
> type t = Bar.t
> end
> module Make(Foo:FOO)(Bar:BAR) : Foo(Bar) with type u = string
>
> but it does not:
>
> Error: Ill-typed functor application Foo(Bar)
>
> The closest I can see is this:
>
> module type BAR = sig
> type t
> end
>
>
> module type FOO = sig
> type u
> type t
> end
>
> module Make(Bar:BAR) : FOO with type u = string and type t = Bar.t
>
> This is already an advanced question, I suggest you ask on the caml-list.
>
> Philippe.
>
>
>
> 2014-06-02 16:09 GMT+02:00 Chantal Keller [email protected]
> [ocaml_beginners] <[email protected]>:
>
>> Dear OCaml users,
>>
>> In a .mli file, I can write the following:
>>
>>
>> module type BAR = sig
>> type t
>> end
>>
>> module type FOO = functor (Bar:BAR) -> sig
>> type u
>> type t = Bar.t
>> end
>>
>> module Make : FOO
>>
>>
>> but I would like to specialize the last line to express the following
>> idea:
>>
>>
>> module Make : FOO with type u = string
>>
>>
>> Is it possible without expanding the signature FOO?
>>
>> Thanks in advance,
>> Chantal.
>>
>>
>> ------------------------------------
>> Posted by: Chantal Keller <[email protected]>
>> ------------------------------------
>>
>> Archives up to December 31, 2011 are also downloadable at
>> http://www.connettivo.net/cntprojects/ocaml_beginners
>> The archives of the very official ocaml list (the seniors' one) can be
>> found at http://caml.inria.fr
>> Attachments are banned and you're asked to be polite, avoid flames
>> etc.Yahoo Groups Links
>>
>>
>>
>
>
>
>