caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Quizz
@ 2015-01-13 17:09 Thomas Braibant
  2015-01-13 20:51 ` Leo White
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Braibant @ 2015-01-13 17:09 UTC (permalink / raw)
  To: OCaML Mailing List

Hi list,

Here is a quizz that can easily be solved using OCaml (version
4.02.1), but it would be less fun than trying to infer which functions
are accepted.

```
module type S = sig val test : 'a list end

type t = (module S)

let a (x : t) =
  let module M = (val x) in
  List.length M.test

let b (module M : S) =
  List.length M.test

let c ((module M) : t) =
  List.length M.test

let d (module M : t) =
  List.length M.test

let e (x : (module S)) =
  let module M = (val x) in
  List.length M.test

let f ((module M) : (module S)) =
  List.length M.test

let g : (module S) -> int = fun (module M) ->
  List.length M.test

let h ((module M) : (module sig val test : 'a list end)) =
  List.length M.test

```
(I am sure I have missed interesting variations, though.)

I have read through

http://caml.inria.fr/pub/docs/manual-ocaml/types.html,
http://caml.inria.fr/pub/docs/manual-ocaml/modtypes.html
http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec230

but what I do not get is how to make a variation of `h` work. That is,
I would like to inline the module signature. Is that possible?

Best,
Thomas

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

* Re: [Caml-list] Quizz
  2015-01-13 17:09 [Caml-list] Quizz Thomas Braibant
@ 2015-01-13 20:51 ` Leo White
  2015-01-13 21:10   ` Milan Stanojević
  0 siblings, 1 reply; 8+ messages in thread
From: Leo White @ 2015-01-13 20:51 UTC (permalink / raw)
  To: Thomas Braibant; +Cc: OCaML Mailing List

Hi,

In OCaml 4.01 and earlier, first-class modules were typed
nominatively. In other words, their type was based on the name of the
module type used, not its structure. For example:

            OCaml version 4.01.0

    # module type T = sig type t end;;
    module type T = sig type t end

    # module type S = sig type t end;;
    module type S = sig type t end

    # let f (x : (module T)) : (module S) = x;;
    Characters 38-39:
      let f (x : (module T)) : (module S) = x;;
                                            ^
    Error: This expression has type (module T)
           but an expression was expected of type (module S)

This obviously requires that the module type has a name:

    # type t = (module sig type t end);;
    Characters 17-20:
      type t = (module sig type t end);;
                       ^^^
    Error: Syntax error

In version 4.02, the type-checking of first-class modules was changed to
be structural instead of nominative:

            OCaml version 4.02.1

    # module type T = sig type t end;;
    module type T = sig type t end

    # module type S = sig type t end;;
    module type S = sig type t end

    # let f (x : (module T)) : (module S) = x;;
    val f : (module T) -> (module S) = <fun>

This means that it would now be possible to support first-class modules
for types which have no name, but such support has not yet been
added. (There are some awkward issues around the syntax in relation to
with constraints, but they are probably solvable.)

So, in summary, you can't do that, but it is now at least theoretically
something you could do.

Regards,

Leo

Thomas Braibant <thomas.braibant@gmail.com> writes:

> Hi list,
>
> Here is a quizz that can easily be solved using OCaml (version
> 4.02.1), but it would be less fun than trying to infer which functions
> are accepted.
>
> ```
> module type S = sig val test : 'a list end
>
> type t = (module S)
>
> let a (x : t) =
>   let module M = (val x) in
>   List.length M.test
>
> let b (module M : S) =
>   List.length M.test
>
> let c ((module M) : t) =
>   List.length M.test
>
> let d (module M : t) =
>   List.length M.test
>
> let e (x : (module S)) =
>   let module M = (val x) in
>   List.length M.test
>
> let f ((module M) : (module S)) =
>   List.length M.test
>
> let g : (module S) -> int = fun (module M) ->
>   List.length M.test
>
> let h ((module M) : (module sig val test : 'a list end)) =
>   List.length M.test
>
> ```
> (I am sure I have missed interesting variations, though.)
>
> I have read through
>
> http://caml.inria.fr/pub/docs/manual-ocaml/types.html,
> http://caml.inria.fr/pub/docs/manual-ocaml/modtypes.html
> http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec230
>
> but what I do not get is how to make a variation of `h` work. That is,
> I would like to inline the module signature. Is that possible?
>
> Best,
> Thomas

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

* Re: [Caml-list] Quizz
  2015-01-13 20:51 ` Leo White
@ 2015-01-13 21:10   ` Milan Stanojević
  2015-01-14  0:09     ` Leo White
  0 siblings, 1 reply; 8+ messages in thread
From: Milan Stanojević @ 2015-01-13 21:10 UTC (permalink / raw)
  To: Leo White; +Cc: Thomas Braibant, OCaML Mailing List

> This means that it would now be possible to support first-class modules
> for types which have no name, but such support has not yet been
> added. (There are some awkward issues around the syntax in relation to
> with constraints, but they are probably solvable.)
>
> So, in summary, you can't do that, but it is now at least theoretically
> something you could do.

Are there any concrete plans to add syntax support?

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

* Re: [Caml-list] Quizz
  2015-01-13 21:10   ` Milan Stanojević
@ 2015-01-14  0:09     ` Leo White
  2015-01-14  7:02       ` Jacques Garrigue
  0 siblings, 1 reply; 8+ messages in thread
From: Leo White @ 2015-01-14  0:09 UTC (permalink / raw)
  To: Milan Stanojević; +Cc: Thomas Braibant, OCaML Mailing List

Milan Stanojević <milanst@gmail.com> writes:

>> This means that it would now be possible to support first-class modules
>> for types which have no name, but such support has not yet been
>> added. (There are some awkward issues around the syntax in relation to
>> with constraints, but they are probably solvable.)
>>
>> So, in summary, you can't do that, but it is now at least theoretically
>> something you could do.
>
> Are there any concrete plans to add syntax support?

I don't think there are any concrete plans. Jacques mentioned it was a
possibility in a comment on Mantis:

  http://caml.inria.fr/mantis/view.php?id=6333#c10990

and other than that I don't think anyone has mentioned it.

Regards,

Leo

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

* Re: [Caml-list] Quizz
  2015-01-14  0:09     ` Leo White
@ 2015-01-14  7:02       ` Jacques Garrigue
  2015-01-14 16:32         ` Milan Stanojević
  0 siblings, 1 reply; 8+ messages in thread
From: Jacques Garrigue @ 2015-01-14  7:02 UTC (permalink / raw)
  To: Leo P White; +Cc: Milan Stanojević, Thomas Braibant, OCaml Mailing List

On 2015/01/14 09:09, Leo White wrote:
> 
> Milan Stanojević <milanst@gmail.com> writes:
> 
>>> This means that it would now be possible to support first-class modules
>>> for types which have no name, but such support has not yet been
>>> added. (There are some awkward issues around the syntax in relation to
>>> with constraints, but they are probably solvable.)
>>> 
>>> So, in summary, you can't do that, but it is now at least theoretically
>>> something you could do.
>> 
>> Are there any concrete plans to add syntax support?
> 
> I don't think there are any concrete plans. Jacques mentioned it was a
> possibility in a comment on Mantis:
> 
>  http://caml.inria.fr/mantis/view.php?id=6333#c10990


The main problem is not so much syntax, as the fact it would require to make
all definitions in the Types module mutually recursive. Not only that, but
operations like path substitution need to be mutually recursive in the same
way. So the question is whether the small gain in flexibility is worth making the
implementation more complex.
(Note that an extra gain is that it becomes possible to expand a module type
definition when leaving its scope)

	Jacques

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

* Re: [Caml-list] Quizz
  2015-01-14  7:02       ` Jacques Garrigue
@ 2015-01-14 16:32         ` Milan Stanojević
  2015-01-14 17:24           ` Leo White
  0 siblings, 1 reply; 8+ messages in thread
From: Milan Stanojević @ 2015-01-14 16:32 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: Leo P White, Thomas Braibant, OCaml Mailing List

> The main problem is not so much syntax, as the fact it would require to make
> all definitions in the Types module mutually recursive. Not only that, but
> operations like path substitution need to be mutually recursive in the same
> way. So the question is whether the small gain in flexibility is worth making the
> implementation more complex.
> (Note that an extra gain is that it becomes possible to expand a module type
> definition when leaving its scope)

In my work I mostly just wanted to be able to just do something like
(module M : Intable with type t = t), i.e just specializing existing
module type with "with type =" or "with type :=".
Is this special case any easier to implement?

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

* Re: [Caml-list] Quizz
  2015-01-14 16:32         ` Milan Stanojević
@ 2015-01-14 17:24           ` Leo White
  2015-01-15  9:41             ` Jacques Garrigue
  0 siblings, 1 reply; 8+ messages in thread
From: Leo White @ 2015-01-14 17:24 UTC (permalink / raw)
  To: Milan Stanojević
  Cc: Jacques Garrigue, Thomas Braibant, OCaml Mailing List

Milan Stanojević <milanst@gmail.com> writes:

>> The main problem is not so much syntax, as the fact it would require to make
>> all definitions in the Types module mutually recursive. Not only that, but
>> operations like path substitution need to be mutually recursive in the same
>> way. So the question is whether the small gain in flexibility is worth making the
>> implementation more complex.
>> (Note that an extra gain is that it becomes possible to expand a module type
>> definition when leaving its scope)
>
> In my work I mostly just wanted to be able to just do something like
> (module M : Intable with type t = t), i.e just specializing existing
> module type with "with type =" or "with type :=".
> Is this special case any easier to implement?

"with type t =" already works. I'm not sure, but I think that "with type
t :=" could indeed be implemented without the increased implementation
complexity that Jacques was referring to.

Regards,

Leo

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

* Re: [Caml-list] Quizz
  2015-01-14 17:24           ` Leo White
@ 2015-01-15  9:41             ` Jacques Garrigue
  0 siblings, 0 replies; 8+ messages in thread
From: Jacques Garrigue @ 2015-01-15  9:41 UTC (permalink / raw)
  To: Leo P White; +Cc: Milan Stanojević, Thomas Braibant, OCaml Mailing List

On 2015/01/15 02:24, Leo White wrote:
> 
> Milan Stanojević <milanst@gmail.com> writes:
> 
>>> The main problem is not so much syntax, as the fact it would require to make
>>> all definitions in the Types module mutually recursive. Not only that, but
>>> operations like path substitution need to be mutually recursive in the same
>>> way. So the question is whether the small gain in flexibility is worth making the
>>> implementation more complex.
>>> (Note that an extra gain is that it becomes possible to expand a module type
>>> definition when leaving its scope)
>> 
>> In my work I mostly just wanted to be able to just do something like
>> (module M : Intable with type t = t), i.e just specializing existing
>> module type with "with type =" or "with type :=".
>> Is this special case any easier to implement?
> 
> "with type t =" already works. I'm not sure, but I think that "with type
> t :=" could indeed be implemented without the increased implementation
> complexity that Jacques was referring to.


Indeed it could.
Module type names + non-parameterized constraints are ok, because you only have
to recurse on types, not concrete signatures.

	Jacques

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

end of thread, other threads:[~2015-01-15  9:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-13 17:09 [Caml-list] Quizz Thomas Braibant
2015-01-13 20:51 ` Leo White
2015-01-13 21:10   ` Milan Stanojević
2015-01-14  0:09     ` Leo White
2015-01-14  7:02       ` Jacques Garrigue
2015-01-14 16:32         ` Milan Stanojević
2015-01-14 17:24           ` Leo White
2015-01-15  9:41             ` Jacques Garrigue

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