* [Caml-list] Functor signature "inheritance"
@ 2016-10-28 12:44 Shayne Fletcher
2016-10-28 13:01 ` Nicolas Ojeda Bar
0 siblings, 1 reply; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-28 12:44 UTC (permalink / raw)
To: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 520 bytes --]
If one wants to include a functor signature in another...
module type EQ = sig
type t
val eq : t * t -> bool
end
module type EQ_PROD = functor (X : EQ) (Y : EQ) ->
sig
type t = X.t * Y.t
val eq : t * t -> bool
end
module type ORD = sig
include EQ
val lt : t * t -> bool
end
module type LT_PROD = functor (X : EQ) (Y : EQ) ->
sig
include EQ_PROD (*What do I say here?*)
end
... How does one do that? Is there a syntax for this sort of thing?
--
Shayne Fletcher
[-- Attachment #2: Type: text/html, Size: 2187 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 12:44 [Caml-list] Functor signature "inheritance" Shayne Fletcher
@ 2016-10-28 13:01 ` Nicolas Ojeda Bar
2016-10-28 13:04 ` Shayne Fletcher
2016-10-28 13:14 ` Shayne Fletcher
0 siblings, 2 replies; 16+ messages in thread
From: Nicolas Ojeda Bar @ 2016-10-28 13:01 UTC (permalink / raw)
To: Shayne Fletcher; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 1200 bytes --]
Hi Shayne,
One approach is to name the *output* signature of the functors:
module type EQ_PROD_S = sig
module X : EQ
module Y : EQ
type t = X.t * Y.t
val eq: t * t -> bool
end
module type EQ_PROD = functor (X : EQ) (Y : EQ) ->
EQ_PROD_S with module X := X and module Y := Y
module type ORD_PROD_S = sig
include EQ_PROD_S
val lt : t * t -> bool
end
module type LT_PROD = functor (X : EQ) (Y : EQ) ->
LT_PROD_S with module X := X and module Y := Y
etc.
Cheers,
Nicolas
On Fri, Oct 28, 2016 at 2:44 PM, Shayne Fletcher <
shayne.fletcher.50@gmail.com> wrote:
> If one wants to include a functor signature in another...
>
> module type EQ = sig
> type t
> val eq : t * t -> bool
> end
>
> module type EQ_PROD = functor (X : EQ) (Y : EQ) ->
> sig
> type t = X.t * Y.t
> val eq : t * t -> bool
> end
>
> module type ORD = sig
> include EQ
> val lt : t * t -> bool
> end
>
> module type LT_PROD = functor (X : EQ) (Y : EQ) ->
> sig
> include EQ_PROD (*What do I say here?*)
> end
>
> ... How does one do that? Is there a syntax for this sort of thing?
>
> --
> Shayne Fletcher
>
[-- Attachment #2: Type: text/html, Size: 3579 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 13:01 ` Nicolas Ojeda Bar
@ 2016-10-28 13:04 ` Shayne Fletcher
2016-10-28 13:14 ` Shayne Fletcher
1 sibling, 0 replies; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-28 13:04 UTC (permalink / raw)
To: Nicolas Ojeda Bar; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 209 bytes --]
On Fri, Oct 28, 2016 at 9:01 AM, Nicolas Ojeda Bar <
nicolas.ojeda.bar@lexifi.com> wrote:
> One approach is to name the *output* signature of the functors:
Ooh! Thanks!
--
Shayne Fletcher
[-- Attachment #2: Type: text/html, Size: 654 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 13:01 ` Nicolas Ojeda Bar
2016-10-28 13:04 ` Shayne Fletcher
@ 2016-10-28 13:14 ` Shayne Fletcher
2016-10-28 13:25 ` Nicolas Ojeda Bar
1 sibling, 1 reply; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-28 13:14 UTC (permalink / raw)
To: Nicolas Ojeda Bar; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 955 bytes --]
On Fri, Oct 28, 2016 at 9:01 AM, Nicolas Ojeda Bar <
nicolas.ojeda.bar@lexifi.com> wrote:
>
> One approach is to name the *output* signature of the functors:
>
> module type EQ_PROD_S = sig
> module X : EQ
> module Y : EQ
> type t = X.t * Y.t
> val eq: t * t -> bool
> end
>
Sorry to be a bother. Got another one for you Nicolas!
How do I achieve the intent of this:
module type EQ = sig
type t
val eq : t * t -> bool
end
module type NUM = sig
type t
val from_int : int -> t
val ( + ) : t -> t -> t
end
module type MUL_S = sig
module N : NUM
module E : EQ with type t := N.t
type t = N.t
val mul : t -> t -> t
end
module type MUL = functor (E : EQ) (N : NUM) -> MUL_S with module N := N
and module E := E
The idea is that the modules satisfying EQ and NUM must agree in their type
t and MUL brings them together and adds a 'mul' function.
--
Shayne Fletcher
[-- Attachment #2: Type: text/html, Size: 3102 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 13:14 ` Shayne Fletcher
@ 2016-10-28 13:25 ` Nicolas Ojeda Bar
2016-10-28 13:28 ` Shayne Fletcher
2016-10-29 18:43 ` Shayne Fletcher
0 siblings, 2 replies; 16+ messages in thread
From: Nicolas Ojeda Bar @ 2016-10-28 13:25 UTC (permalink / raw)
To: Shayne Fletcher; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 1328 bytes --]
Hi Shayne,
You can add a constrain to your functor arguments :
module type MUL = functor (E : EQ) (N : NUM with type t = E.t) ->
MUL_S with module N := N and module E := E
Cheers,
Nicolas
On Fri, Oct 28, 2016 at 3:14 PM, Shayne Fletcher <
shayne.fletcher.50@gmail.com> wrote:
>
> On Fri, Oct 28, 2016 at 9:01 AM, Nicolas Ojeda Bar <
> nicolas.ojeda.bar@lexifi.com> wrote:
>
>>
>> One approach is to name the *output* signature of the functors:
>>
>> module type EQ_PROD_S = sig
>> module X : EQ
>> module Y : EQ
>> type t = X.t * Y.t
>> val eq: t * t -> bool
>> end
>>
>
> Sorry to be a bother. Got another one for you Nicolas!
>
> How do I achieve the intent of this:
>
> module type EQ = sig
> type t
> val eq : t * t -> bool
> end
>
> module type NUM = sig
> type t
> val from_int : int -> t
> val ( + ) : t -> t -> t
> end
>
> module type MUL_S = sig
> module N : NUM
> module E : EQ with type t := N.t
>
> type t = N.t
> val mul : t -> t -> t
> end
>
> module type MUL = functor (E : EQ) (N : NUM) -> MUL_S with module N := N
> and module E := E
>
> The idea is that the modules satisfying EQ and NUM must agree in their
> type t and MUL brings them together and adds a 'mul' function.
>
> --
> Shayne Fletcher
>
[-- Attachment #2: Type: text/html, Size: 3953 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 13:25 ` Nicolas Ojeda Bar
@ 2016-10-28 13:28 ` Shayne Fletcher
2016-10-28 13:47 ` rixed
2016-10-28 16:12 ` Shayne Fletcher
2016-10-29 18:43 ` Shayne Fletcher
1 sibling, 2 replies; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-28 13:28 UTC (permalink / raw)
To: Nicolas Ojeda Bar; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 484 bytes --]
On Fri, Oct 28, 2016 at 9:25 AM, Nicolas Ojeda Bar <
nicolas.ojeda.bar@lexifi.com> wrote:
> You can add a constrain to your functor arguments :
>
> module type MUL = functor (E : EQ) (N : NUM with type t = E.t) ->
> MUL_S with module N := N and module E := E
>
That does it! I tried so many different things :) You're a rock 'n roll
star.
We *really* need a comprehensive tutorial or reference on how to express
sharing constraints!
--
Shayne Fletcher
[-- Attachment #2: Type: text/html, Size: 1013 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 13:28 ` Shayne Fletcher
@ 2016-10-28 13:47 ` rixed
2016-10-28 13:55 ` Shayne Fletcher
2016-10-28 16:12 ` Shayne Fletcher
1 sibling, 1 reply; 16+ messages in thread
From: rixed @ 2016-10-28 13:47 UTC (permalink / raw)
To: Shayne Fletcher; +Cc: caml-list@inria.fr users
Best book I've seen about this is this one:
http://www.eyrolles.com/Informatique/Livre/programmation-fonctionnelle-generique-et-objet-9782711748433
unfortunately never translated, and out of print.
That's really a shame.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 13:47 ` rixed
@ 2016-10-28 13:55 ` Shayne Fletcher
2016-10-28 15:44 ` Gabriel Scherer
0 siblings, 1 reply; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-28 13:55 UTC (permalink / raw)
To: rixed; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 272 bytes --]
On Fri, Oct 28, 2016 at 9:47 AM, <rixed@happyleptic.org> wrote:
> unfortunately never translated, and out of print.
> That's really a shame.
>
Truly. I'd even try wading through it in French if it were available
somewhere but alas!
--
Shayne Fletcher
[-- Attachment #2: Type: text/html, Size: 778 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 13:55 ` Shayne Fletcher
@ 2016-10-28 15:44 ` Gabriel Scherer
2016-10-29 1:59 ` Shayne Fletcher
0 siblings, 1 reply; 16+ messages in thread
From: Gabriel Scherer @ 2016-10-28 15:44 UTC (permalink / raw)
To: Shayne Fletcher; +Cc: Cedric Cellier, caml-list@inria.fr users
This book can be found in online repositories (do you know about the
Library Genesis project?), but I don't think it can be diffused
without a copyright violation. If the list is out of print, the author
should be able to ask for it to be either reprinted, or to recover
diffusion rights for it -- and thus make it available online if they
so desire. But that is a procedure that (as understood in French law)
only the author can perform, I believe.
On Fri, Oct 28, 2016 at 9:55 AM, Shayne Fletcher
<shayne.fletcher.50@gmail.com> wrote:
>
> On Fri, Oct 28, 2016 at 9:47 AM, <rixed@happyleptic.org> wrote:
>>
>> unfortunately never translated, and out of print.
>> That's really a shame.
>
>
> Truly. I'd even try wading through it in French if it were available
> somewhere but alas!
>
> --
> Shayne Fletcher
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 15:44 ` Gabriel Scherer
@ 2016-10-29 1:59 ` Shayne Fletcher
0 siblings, 0 replies; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-29 1:59 UTC (permalink / raw)
To: Gabriel Scherer; +Cc: caml-list@inria.fr users, Chapi Chapo
[-- Attachment #1: Type: text/plain, Size: 560 bytes --]
On Oct 28, 2016 11:45 AM, "Gabriel Scherer" <gabriel.scherer@gmail.com>
wrote:
>
> This book can be found in online repositories (do you know about the
> Library Genesis project?), but I don't think it can be diffused
> without a copyright violation. If the list is out of print, the author
> should be able to ask for it to be either reprinted, or to recover
> diffusion rights for it -- and thus make it available online if they
> so desire. But that is a procedure that (as understood in French law)
> only the author can perform, I believe.
Copy. Thanks.
[-- Attachment #2: Type: text/html, Size: 738 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 13:28 ` Shayne Fletcher
2016-10-28 13:47 ` rixed
@ 2016-10-28 16:12 ` Shayne Fletcher
2016-10-28 16:16 ` Shayne Fletcher
2016-10-28 16:17 ` Nicolas Ojeda Bar
1 sibling, 2 replies; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-28 16:12 UTC (permalink / raw)
To: Nicolas Ojeda Bar; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 1392 bytes --]
On Fri, Oct 28, 2016 at 9:28 AM, Shayne Fletcher <
shayne.fletcher.50@gmail.com> wrote:
> On Fri, Oct 28, 2016 at 9:25 AM, Nicolas Ojeda Bar <
> nicolas.ojeda.bar@lexifi.com> wrote:
>
>> You can add a constrain to your functor arguments :
>>
>> module type MUL = functor (E : EQ) (N : NUM with type t = E.t) ->
>> MUL_S with module N := N and module E := E
>>
>
> That does it! I tried so many different things :) You're a rock 'n roll
> star.
>
Still stuck on how to achieve this I'm afraid.
module type EQ = sig
type t
val eq : t * t -> bool
end
module type NUM = sig
type t
val from_int : int -> t
val ( + ) : t -> t -> t
end
module type MUL_S = sig
include EQ
include NUM with type t := t
val mul : t -> t -> t
end
module type MUL = functor (E : EQ) (N : NUM with type t = E.t) -> MUL_S
module Mul_default (E : EQ) (N : NUM with type t = E.t) : MUL = struct
include E
include (N : NUM with type t := E.t)
let mul (x : t) (y : t) : t = failwith "foo"
end
Yields.
Error: Signature mismatch:
Modules do not match:
sig
type t = E.t
val eq : t * t -> bool
val from_int : int -> E.t
val ( + ) : E.t -> E.t -> E.t
val mul : t -> t -> t
end
is not included in
MUL
--
Shayne Fletcher
[-- Attachment #2: Type: text/html, Size: 5259 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 16:12 ` Shayne Fletcher
@ 2016-10-28 16:16 ` Shayne Fletcher
2016-10-28 16:17 ` Shayne Fletcher
2016-10-28 16:17 ` Nicolas Ojeda Bar
1 sibling, 1 reply; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-28 16:16 UTC (permalink / raw)
To: Nicolas Ojeda Bar; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 444 bytes --]
On Fri, Oct 28, 2016 at 12:12 PM, Shayne Fletcher <
shayne.fletcher.50@gmail.com> wrote:
> Still stuck on how to achieve this I'm afraid.
>
Ah wait. I think I've got it.
module Mul_default (E : EQ) (N : NUM with type t = E.t) : MUL_S = struct
type t = E.t
include (E : EQ with type t := t)
include (N : NUM with type t := t)
let mul (x : t) (y : t) : t = failwith "foo"
end
--
Shayne Fletcher
[-- Attachment #2: Type: text/html, Size: 1669 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 16:12 ` Shayne Fletcher
2016-10-28 16:16 ` Shayne Fletcher
@ 2016-10-28 16:17 ` Nicolas Ojeda Bar
2016-10-28 16:36 ` Shayne Fletcher
1 sibling, 1 reply; 16+ messages in thread
From: Nicolas Ojeda Bar @ 2016-10-28 16:17 UTC (permalink / raw)
To: Shayne Fletcher; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 1868 bytes --]
Hi Shayne,
I did not try it, but I think you want
module Mul_default : MUL = functor (E : EQ) (N : NUM with type t = E.t) ->
struct
include E
include (N : NUM with type t := E.t)
let mul (x : t) (y : t) : t = failwith "foo"
end
Cheers,
Nicolas
On Fri, Oct 28, 2016 at 6:12 PM, Shayne Fletcher <
shayne.fletcher.50@gmail.com> wrote:
>
> On Fri, Oct 28, 2016 at 9:28 AM, Shayne Fletcher <
> shayne.fletcher.50@gmail.com> wrote:
>
>> On Fri, Oct 28, 2016 at 9:25 AM, Nicolas Ojeda Bar <
>> nicolas.ojeda.bar@lexifi.com> wrote:
>>
>>> You can add a constrain to your functor arguments :
>>>
>>> module type MUL = functor (E : EQ) (N : NUM with type t = E.t) ->
>>> MUL_S with module N := N and module E := E
>>>
>>
>> That does it! I tried so many different things :) You're a rock 'n roll
>> star.
>>
>
> Still stuck on how to achieve this I'm afraid.
>
> module type EQ = sig
> type t
> val eq : t * t -> bool
> end
>
> module type NUM = sig
> type t
> val from_int : int -> t
> val ( + ) : t -> t -> t
> end
>
> module type MUL_S = sig
> include EQ
> include NUM with type t := t
>
> val mul : t -> t -> t
> end
>
> module type MUL = functor (E : EQ) (N : NUM with type t = E.t) -> MUL_S
>
> module Mul_default (E : EQ) (N : NUM with type t = E.t) : MUL = struct
>
> include E
> include (N : NUM with type t := E.t)
>
> let mul (x : t) (y : t) : t = failwith "foo"
>
> end
>
> Yields.
>
> Error: Signature mismatch:
> Modules do not match:
> sig
> type t = E.t
> val eq : t * t -> bool
> val from_int : int -> E.t
> val ( + ) : E.t -> E.t -> E.t
> val mul : t -> t -> t
> end
> is not included in
> MUL
>
> --
> Shayne Fletcher
>
[-- Attachment #2: Type: text/html, Size: 6329 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 16:17 ` Nicolas Ojeda Bar
@ 2016-10-28 16:36 ` Shayne Fletcher
0 siblings, 0 replies; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-28 16:36 UTC (permalink / raw)
To: Nicolas Ojeda Bar; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 945 bytes --]
On Fri, Oct 28, 2016 at 12:17 PM, Nicolas Ojeda Bar <
nicolas.ojeda.bar@lexifi.com> wrote:
> I did not try it, but I think you want
>
> module Mul_default : MUL = functor (E : EQ) (N : NUM with type t = E.t)
> -> struct
> include E
> include (N : NUM with type t := E.t)
>
> let mul (x : t) (y : t) : t = failwith "foo"
> end
>
Phew!
module type EQ = sig
type t
val eq : t * t -> bool
end
module type NUM = sig
type t
val from_int : int -> t
val ( + ) : t -> t -> t
end
module type MUL_basic = sig
type t
val mul : t -> t -> t
end
module type MUL = functor (E : EQ) (N : NUM with type t = E.t) -> MUL_basic
module Mul_default : MUL = functor (E : EQ) (N : NUM with type t = E.t) ->
struct
include E
include (N : NUM with type t := E.t)
let mul (x : t) (y : t) : t = failwith "foo"
end
Thanks Nicolas. Lot to learn here!
--
Shayne Fletcher
[-- Attachment #2: Type: text/html, Size: 3330 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Caml-list] Functor signature "inheritance"
2016-10-28 13:25 ` Nicolas Ojeda Bar
2016-10-28 13:28 ` Shayne Fletcher
@ 2016-10-29 18:43 ` Shayne Fletcher
1 sibling, 0 replies; 16+ messages in thread
From: Shayne Fletcher @ 2016-10-29 18:43 UTC (permalink / raw)
To: Nicolas Ojeda Bar; +Cc: caml-list@inria.fr users
[-- Attachment #1: Type: text/plain, Size: 565 bytes --]
On Fri, Oct 28, 2016 at 9:25 AM, Nicolas Ojeda Bar <
nicolas.ojeda.bar@lexifi.com> wrote:
> You can add a constrain to your functor arguments :
Thanks again for all your help, rixed, Gabriel, Nicolas! I wrote up all
that I learned in this exercise, here
<http://t.sidekickopen68.com/e1t/c/5/f18dQhb0S7lC8dDMPbW2n0x6l2B9nMJW7t5XZs7dSpxYMRJm4bRbwtnW2zhqcR56dRtXf5pnn5l02?t=http%3A%2F%2Fblog.shaynefletcher.org%2F2016%2F10%2Fimplementing-type-classes-as-ocaml.html&si=5384785918689280&pi=b7eb6b4a-9ca6-4f00-cb44-c90db32d717e>
.
--
Shayne Fletcher
[-- Attachment #2: Type: text/html, Size: 1272 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2016-10-29 18:43 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-28 12:44 [Caml-list] Functor signature "inheritance" Shayne Fletcher
2016-10-28 13:01 ` Nicolas Ojeda Bar
2016-10-28 13:04 ` Shayne Fletcher
2016-10-28 13:14 ` Shayne Fletcher
2016-10-28 13:25 ` Nicolas Ojeda Bar
2016-10-28 13:28 ` Shayne Fletcher
2016-10-28 13:47 ` rixed
2016-10-28 13:55 ` Shayne Fletcher
2016-10-28 15:44 ` Gabriel Scherer
2016-10-29 1:59 ` Shayne Fletcher
2016-10-28 16:12 ` Shayne Fletcher
2016-10-28 16:16 ` Shayne Fletcher
2016-10-28 16:17 ` Shayne Fletcher
2016-10-28 16:17 ` Nicolas Ojeda Bar
2016-10-28 16:36 ` Shayne Fletcher
2016-10-29 18:43 ` Shayne Fletcher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox