caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] module and it's types as function parameters
@ 2017-11-23 12:52 Serge Sivkov
  2017-11-23 13:14 ` Nicolás Ojeda Bär
  0 siblings, 1 reply; 3+ messages in thread
From: Serge Sivkov @ 2017-11-23 12:52 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 469 bytes --]

Hello,

is there way to define module with similar interface:

module R = struct
        type topicf = (module F : I) -> F.message -> F.message
        and topic = { func: topicf; name: string }
        ...
end

it is possible in case I want to define function with similar signature I
can declare used types by:
let test (type message') (module M : I with type message = message') (v:
message') : message' = ...

But how should I create such type in module?

WBR, ssp

[-- Attachment #2: Type: text/html, Size: 649 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] module and it's types as function parameters
  2017-11-23 12:52 [Caml-list] module and it's types as function parameters Serge Sivkov
@ 2017-11-23 13:14 ` Nicolás Ojeda Bär
  2017-11-24  5:27   ` Serge Sivkov
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolás Ojeda Bär @ 2017-11-23 13:14 UTC (permalink / raw)
  To: Serge Sivkov; +Cc: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1042 bytes --]

Dear Serge,

If I understand correctly what you are asking, then you can make it work by
wrapping the definition of topicf in an existential:

  module R = struct
    type topicf = TF : ((module I with type message = 'a) -> 'a -> 'a) ->
topicf
    and topic = { func: topicf; name: string }
    ...
  end

then, given test, you can create an R.topic by doing

  { R.func = TF test; name = "test" }

Best wishes,
Nicolás


On Thu, Nov 23, 2017 at 1:52 PM, Serge Sivkov <ssp.mryau@gmail.com> wrote:

> Hello,
>
> is there way to define module with similar interface:
>
> module R = struct
>         type topicf = (module F : I) -> F.message -> F.message
>         and topic = { func: topicf; name: string }
>         ...
> end
>
> it is possible in case I want to define function with similar signature I
> can declare used types by:
> let test (type message') (module M : I with type message = message') (v:
> message') : message' = ...
>
> But how should I create such type in module?
>
> WBR, ssp
>

[-- Attachment #2: Type: text/html, Size: 1674 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] module and it's types as function parameters
  2017-11-23 13:14 ` Nicolás Ojeda Bär
@ 2017-11-24  5:27   ` Serge Sivkov
  0 siblings, 0 replies; 3+ messages in thread
From: Serge Sivkov @ 2017-11-24  5:27 UTC (permalink / raw)
  To: Nicolás Ojeda Bär; +Cc: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1262 bytes --]

Dear Nicolás,

thank you very match, it works as I wish :)

WBR, ssp

2017-11-23 18:14 GMT+05:00 Nicolás Ojeda Bär <nicolas.ojeda.bar@lexifi.com>:

> Dear Serge,
>
> If I understand correctly what you are asking, then you can make it work
> by wrapping the definition of topicf in an existential:
>
>   module R = struct
>     type topicf = TF : ((module I with type message = 'a) -> 'a -> 'a) ->
> topicf
>     and topic = { func: topicf; name: string }
>     ...
>   end
>
> then, given test, you can create an R.topic by doing
>
>   { R.func = TF test; name = "test" }
>
> Best wishes,
> Nicolás
>
>
> On Thu, Nov 23, 2017 at 1:52 PM, Serge Sivkov <ssp.mryau@gmail.com> wrote:
>
>> Hello,
>>
>> is there way to define module with similar interface:
>>
>> module R = struct
>>         type topicf = (module F : I) -> F.message -> F.message
>>         and topic = { func: topicf; name: string }
>>         ...
>> end
>>
>> it is possible in case I want to define function with similar signature I
>> can declare used types by:
>> let test (type message') (module M : I with type message = message') (v:
>> message') : message' = ...
>>
>> But how should I create such type in module?
>>
>> WBR, ssp
>>
>
>

[-- Attachment #2: Type: text/html, Size: 2407 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-24  5:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-23 12:52 [Caml-list] module and it's types as function parameters Serge Sivkov
2017-11-23 13:14 ` Nicolás Ojeda Bär
2017-11-24  5:27   ` Serge Sivkov

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).