From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Andre Nathan <andre@digirati.com.br>
Cc: Arnaud Spiwack <aspiwack@lix.polytechnique.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] What am I reinventing here?
Date: Tue, 14 Feb 2012 11:39:42 +0100 [thread overview]
Message-ID: <CAPFanBEwqDjciwwy8nWxj21tuQ-_C6SnU3Ys=5zA3HsXjkTdVg@mail.gmail.com> (raw)
In-Reply-To: <1329215040.13129.3.camel@andre>
Yes it is, but you have to use judicious "with .." annotations to make
the type non-abstract.
Silly example that captures the problem I think you're thinking of:
module type S = sig
type t
val v : t
end
type foo = A | B
module M = struct
type t = foo
let v = A
end
let () = match M.v with A -> () | B -> ()
(* works *)
module M2 = (M : S)
let () = match M2.v with A -> () | B -> ()
(* Error: This pattern matches values of type foo
but a pattern was expected which matches values of type M2.t *)
module M3 = (M : S with type t = foo)
let () = match M3.v with A -> () | B -> ()
(* works *)
In your case, you should write (module Make(O : Ops) : S with type foo
= ... and bar = ...).
On Tue, Feb 14, 2012 at 11:24 AM, Andre Nathan <andre@digirati.com.br> wrote:
> On Tue, 2012-02-14 at 11:09 +0100, Gabriel Scherer wrote:
>> Here is an attempt at a functor translation. Note that's it's mostly a
>> glorified way to do exactly the same thing. Passing a module or a
>> record of operation is not very different; yet a module can carry
>> types so you don't have to parametrize your operations explicitly.
>
> Thank you Gabriel.
>
>> module Make (O : OPS) = struct
>> let foo = O.bar_of_foo
>> let bar = O.foo_of_bar
>> end
>
> Would it be correct to say that it isn't possible to specify a signature
> S for the output module like
>
> module Make (O : OPS) : S = struct
> ...
> end
>
> that would still make pattern-matching outside of the module possible?
>
> Thanks,
> Andre
>
next prev parent reply other threads:[~2012-02-14 10:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-13 23:33 Andre Nathan
2012-02-14 7:03 ` Arnaud Spiwack
2012-02-14 9:59 ` Andre Nathan
2012-02-14 10:09 ` Gabriel Scherer
2012-02-14 10:24 ` Andre Nathan
2012-02-14 10:39 ` Gabriel Scherer [this message]
2012-02-14 11:05 ` Andre Nathan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPFanBEwqDjciwwy8nWxj21tuQ-_C6SnU3Ys=5zA3HsXjkTdVg@mail.gmail.com' \
--to=gabriel.scherer@gmail.com \
--cc=andre@digirati.com.br \
--cc=aspiwack@lix.polytechnique.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox