caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Arnaud Spiwack <Arnaud.Spiwack@lix.polytechnique.fr>
To: OCaML Mailing List <caml-list@inria.fr>
Subject: [Caml-list] One-value functors
Date: Fri, 11 May 2012 12:03:32 +0200	[thread overview]
Message-ID: <CAMoPVjchxsQ5QDdsfBU+TDVmhAxrBUndDNJzVP==WT1vcE8gcw@mail.gmail.com> (raw)

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

Dear all,

With the advent of first-class modules, I find myself more and more wanting
to write functors with only one (value) component, just to benefit from
type dependencies. Here is an example (randomly) extracted from Oleg
Kiselyov and Jeremy Yallop:

type a and b
> module type TC = sig type 'a t end
> module type Subst = functor (A:TC) -> sig val x : a A.t -> b A.t end
>

If this pattern had to become widespread, it would be worth agreeing for a
name on the single component, though it's a bit unnecessary to need a name
at all.
It get very verbose, though, when trying to applying the functor. Supposing
I have a module Subst:Subst :

let module S = Subst(sig type 'a t = 'a list) in
> S.x …
>

Nothing terrible really, but it sort of gets in the way. I can see benefit
in having a special syntax for this sort of definition. I think we could
take advantage of first-class functors to get something quite modular, here
is a mockup syntax:

We could have the type

(X:A) => t
>

stand for (something like)

module F = functor (X:A) -> sig val x : t end
>
(module F)
>

and the definition

let f {{X:A}} = e
>

stand for

let f = let module F (X:A) -> struct let x = e end
>

and finally we'd need an application

e {{M}}
>

would stand for (something like)

let module F = (val e) in let module F' = F(M) in F'.x
>


Clearly the application needs something like OCaml 4.0 and the type
definition some kind of cleverness (I don't know, by the way, why the
syntax for F cannot be inlined in the type).

In this example syntax the above example would look like

type a and b
> module type TC = sig type 'a t end
> val subst : (A:TC) => a A.t -> b B.t
>
> subst {{sig type 'a t = 'a list end}} …
>

I believe this would be something cool to have, so I came with two
questions:
1/ Is there some demand for this kind of things (if not, I'm not sure it's
worth pursuing, though of course demand could appear after supply)
2/ I don't see how to define the type syntax in camlp4, because of the
inlining thing, could it be done?
   (an alternative may be to have (X:A) => t be a module type, but then
(X:A) => (Y:B) => t is not a valid type, so we would need syntaxes for
n-ary abstraction/applications)

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

             reply	other threads:[~2012-05-11 10:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-11 10:03 Arnaud Spiwack [this message]
2012-05-17 14:52 ` Goswin von Brederlow
2012-05-17 16:23 ` Nicolas Braud-Santoni
2012-05-21  9:25   ` Arnaud Spiwack
2012-05-30 14:14     ` Arnaud Spiwack

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='CAMoPVjchxsQ5QDdsfBU+TDVmhAxrBUndDNJzVP==WT1vcE8gcw@mail.gmail.com' \
    --to=arnaud.spiwack@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).