caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Berke Durak <berke.durak@gmail.com>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] Trying to define a functor combining polymorphic variants
Date: Sat, 3 May 2014 10:43:46 +0900	[thread overview]
Message-ID: <DD57D715-4E49-469D-A7F5-0F288F1A5C95@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAALTfKAgRe8EnL60-PavnnbqHFfnRKABNUkqE0hWkE+Q-sGYuA@mail.gmail.com>

On 2014/05/03 00:50, Berke Durak wrote:
> 
> Thanks Leo and Jacques for the responses.
> 
> Jacques, if the PROD functor has to have a compatibility tag, doesn't
> it mean that you can't reuse it to generate large products?  i.e. how
> would one write: A*B*C*D = PROD(A)(PROD(B)(PROD(C)(D))))?

The compatibility annotation is on the functor. If the variant types
in the modules you pass to the functor are concrete, they don’t need
annotations.
If you want to define a 4-ary functor that calls PROD, then its arguments
will need annotations too, of course.

For the details, you can see the internship report by Romain Bardou (in French):
Unions de variants polymorphes abstraits
http://www.math.nagoya-u.ac.jp/~garrigue/papers/index.html

Jacques Garrigue

> On Fri, May 2, 2014 at 2:14 AM, Jacques Garrigue
> <garrigue@math.nagoya-u.ac.jp> wrote:
>> On 2014/05/02 05:58, Berke Durak wrote:
>>> So I naturally wanted to write a functor that does what the module AB does:
>>> 
>>> module type S = sig
>>>   type message
>>>   val string_of_message : message -> string
>>> end
>>> 
>>> module PROD(A : S)(B : S) = struct
>>>   type message = [ A.message | B.message ]
>>>   let string_of_message = function
>>>   | #A.t as msg -> A.string_of_message msg
>>>   | #B.t as msg -> B.string_of_message msg
>>> end
>>> 
>>> But we (me + people on #ocaml: mrvn, drup, ggole, whitequark...) couldn't find a
>>> way to specify, in the signature S, that message is a polymorphic variant so
>>> that [ A.message | B.message ] is legal.
>> 
>> There is a branch of the compiler which allows you to do that.
>> 
>>        http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/varunion/
>> 
>> Note that it contains only part of the directories. You can get the others
>> from a pristine 3.10.
>> 
>> Using that version, you would write:
>>  module type S = sig
>>     type message = private [> ]
>>     …
>>  end
>> 
>>  module PROD (A : S) (B : S with type message = private [> ] ~ A.message) = …
>> 
>> where the ~ is a compatibility annotation.
>> 
>> This was never merged because I couldn’t find a clean way to fix some gap between
>> theory and practice, but I may give it another try.
>> Keigo Imai used it in his async_session code.
>> 
>> https://github.com/keigoi/async_session/blob/master/varunion_session.ml
>> 
>> Jacques Garrigue



      reply	other threads:[~2014-05-03  1:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-01 20:58 Berke Durak
2014-05-01 23:55 ` Leo White
2014-05-02  6:14 ` Jacques Garrigue
2014-05-02 15:50   ` Berke Durak
2014-05-03  1:43     ` Jacques Garrigue [this message]

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=DD57D715-4E49-469D-A7F5-0F288F1A5C95@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=berke.durak@gmail.com \
    --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).