caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
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:09:46 +0100	[thread overview]
Message-ID: <CAPFanBFtLh7rkmUdv4iXzSsMdMckr0FX_uKqenDAsX53oOwZiQ@mail.gmail.com> (raw)
In-Reply-To: <1329213575.13129.0.camel@andre>

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.

module type OPS = sig
  type bar
  type foo
  val bar_of_foo : foo -> bar
  val foo_of_bar : bar -> foo
end

module Make (O : OPS) = struct
  let foo = O.bar_of_foo
  let bar = O.foo_of_bar
end

module Op1 = struct
  type foo = A | B
  type bar = C | D
  let bar_of_foo = function A -> C | B -> D
  let foo_of_bar = function C -> A | D -> B
end

let () =
 let module M = Make(Op1) in
 (* you may want to open Op1 locally here *)
 match M.foo Op1.A with
 | Op1.C -> ()
 | Op1.D -> ()


On Tue, Feb 14, 2012 at 10:59 AM, Andre Nathan <andre@digirati.com.br> wrote:
> On Tue, 2012-02-14 at 08:03 +0100, Arnaud Spiwack wrote:
>> You're probably trying to use functors
>> ( http://caml.inria.fr/pub/docs/manual-ocaml/manual004.html#toc15 ).
>> Though your example code isn't doing anything in particular.
>
> Can you give me an example? How can I retain the possibility of
> pattern-matching on the types of the resulting module?
>
> Thanks,
> Andre
>>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2012-02-14 10:10 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 [this message]
2012-02-14 10:24       ` Andre Nathan
2012-02-14 10:39         ` Gabriel Scherer
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=CAPFanBFtLh7rkmUdv4iXzSsMdMckr0FX_uKqenDAsX53oOwZiQ@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;
as well as URLs for NNTP newsgroup(s).