Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Julien Signoles <julien.signoles@gmail.com>
To: Alain Frisch <alain.frisch@lexifi.com>
Cc: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>,
	caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] What is an applicative functor?
Date: Fri, 8 Apr 2011 13:25:13 +0200	[thread overview]
Message-ID: <BANLkTikWxjMtFHWShMFA5vKdi29dUsj1vw@mail.gmail.com> (raw)
In-Reply-To: <4D9ECAF2.7070300@lexifi.com>

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

Hello,

2011/4/8 Alain Frisch <alain.frisch@lexifi.com>

> On 04/08/2011 10:20 AM, Jacques Garrigue wrote:
>
>> Applicative functors have other advantages, like the fact you can refer to
>> a
>> type produced by a functor without having really applied it.
>>
>> For instance think of the following functor definition
>>
>>    module F(O : Set.OrderedType)(S : sig type t = Set.Make(O).t val union
>> : t ->  t ->  t end) = ...
>>
>> If you want to do the same thing with generative functors, I believe you
>> have to
>> pass the result of Set.Make(O) around physically.
>> I do think this is a significant weakness.
>>
>
> I can imagine uses for:
>
> module F(O : Set.OrderedType)(S : Set.S with type elt = O.t) =
>
> but I don't see a real-life case where one would want functor F to know
> that the type S.t was really produced by applying Set.Make.  Do you have a
> specific example in mind?
>

I just try to compile Frama-C (http://frama-c.com) with the option
-no-app-funct in order to discover where/why we need applicative functors (I
knew that we use them somewhere).
I found three different patterns:

1) module M = F(G(X))

Without applicative functors, we get the error "The parameter cannot be
eliminated in the result type. Please bind the argument to a module
identifier.". That is easy to fix by introducing an intermediate module.

2) module F(X:...) = G(H(X))

Without applicative functors, we again get the error about parameter
elimination. But I see no workaround to eliminate it without changing the
signature of F. So IMHO that is a use case where applicative functors are
useful.

3) type t = F(X).t
    type u = { a: t }
These declarations are in a single .mli file without a corresponding .ml
file. G(X).t is an abstract type. Generators of values of type u are in a
module F while users of type u are others modules. Also we have to solve an
usual issue with mutual dependencies between F and its users. But the type u
is one of the most useful type in Frama-C. Thus standard solution to the
mutual dependencies issues which use polymorphism or functor are too heavy
here. That is the lightweight solution that we found.

To summarize:
- case 1 may be easily solved by writting 2 lines of code instead of 1
- case 2 and 3 may be circumvented for sure, but the solutions that I have
in mind are heavy

To conclude, there are only few use case where applicative functors are
useful in an application like Frama-C (where there are thousands of functor
applications). But IMHO that are enough cases to answer: yes applicative
functors are (sometimes) useful.

--
Julien

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

  parent reply	other threads:[~2011-04-08 11:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-07 21:12 Dawid Toton
2011-04-07 21:49 ` Gerd Stolpmann
2011-04-08  0:44   ` [Caml-list] " Dawid Toton
2011-04-08  1:34     ` Gerd Stolpmann
2011-04-08  6:50   ` [Caml-list] " Andreas Rossberg
2011-04-08  8:04     ` Alain Frisch
2011-04-08  8:20       ` Jacques Garrigue
2011-04-08  8:38         ` Jacques Garrigue
2011-04-08  8:44         ` Alain Frisch
2011-04-08 10:09           ` Jacques Garrigue
2011-04-08 11:25           ` Julien Signoles [this message]
2011-04-08 11:58             ` Alain Frisch
2011-04-11  7:10               ` Julien Signoles
2011-04-11  7:21                 ` Julien Signoles
2011-04-08 13:43           ` rossberg
2011-04-08 16:26             ` Julien Signoles
2011-04-13  2:36             ` Lucas Dixon
2011-04-13  7:23               ` Andreas Rossberg
2011-04-15  3:08                 ` Lucas Dixon
2011-04-19 14:04                   ` Andreas Rossberg
2011-04-08 16:43     ` Till Varoquaux
2011-04-08 17:35       ` Alain Frisch
2011-04-08 18:44       ` Andreas Rossberg
2011-04-08 21:23     ` Lauri Alanko
2011-04-08 21:34       ` Guillaume Yziquel
2011-04-09 11:41       ` Andreas Rossberg
2011-04-08  5:35 ` Stefan Holdermans

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=BANLkTikWxjMtFHWShMFA5vKdi29dUsj1vw@mail.gmail.com \
    --to=julien.signoles@gmail.com \
    --cc=alain.frisch@lexifi.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /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