caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Arnaud Spiwack <aspiwack@lix.polytechnique.fr>
To: Andre Nathan <andre@digirati.com.br>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] What am I reinventing here?
Date: Tue, 14 Feb 2012 08:03:00 +0100	[thread overview]
Message-ID: <CAMoPVjf2RnHHh=piQEh3dgbBUarQhx_EBT=Ni3EenosPpn0Dfw@mail.gmail.com> (raw)
In-Reply-To: <4F399DD5.3000507@digirati.com.br>

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

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.

On 14 February 2012 00:33, Andre Nathan <andre@digirati.com.br> wrote:

> Hello
>
> I have some code that behaves like the following.
>
> module M = struct
>  type ('a, 'b) ops = {
>    bar_of_foo : 'a -> 'b;
>    foo_of_bar : 'b -> 'a
>  }
>
>  let foo ops x = ops.bar_of_foo x
>  let bar ops x = ops.foo_of_bar x
> end
>
> type foo = A | B
> type bar = C | D
>
> let ops = {
>  M.bar_of_foo = (function A -> C | B -> D);
>  M.foo_of_bar = (function C -> A | D -> B)
> }
>
> let () =
>  match M.foo ops A with
>  | C -> ()
>  | D -> ()
>
> The idea is to parametrize the behavior of some module M on two types and
> a set of operations involving these two types, with the catch that I want
> to keep the ability to pattern-match on the possible values of these types
> in the code that handles the return values from the functions exported by M.
>
> With the scheme above I can do this, but passing a table of functions
> around doesn't look very nice. Is there any way I can use functors to do
> what this code does, while still being able to use pattern-matching? Would
> I have to resort to objects to be able to do this?
>
> Thanks in advance,
> Andre
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/**wws/info/caml-list<https://sympa-roc.inria.fr/wws/info/caml-list>
> Beginner's list: http://groups.yahoo.com/group/**ocaml_beginners<http://groups.yahoo.com/group/ocaml_beginners>
> Bug reports: http://caml.inria.fr/bin/caml-**bugs<http://caml.inria.fr/bin/caml-bugs>
>
>

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

  reply	other threads:[~2012-02-14  7:03 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 [this message]
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
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='CAMoPVjf2RnHHh=piQEh3dgbBUarQhx_EBT=Ni3EenosPpn0Dfw@mail.gmail.com' \
    --to=aspiwack@lix.polytechnique.fr \
    --cc=andre@digirati.com.br \
    --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).