From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Dawid Toton <d0@wp.pl>
Cc: caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Re: What is an applicative functor?
Date: Fri, 08 Apr 2011 03:34:39 +0200 [thread overview]
Message-ID: <1302226479.8429.1154.camel@thinkpad> (raw)
In-Reply-To: <4D9E5A80.3010902@wp.pl>
Am Freitag, den 08.04.2011, 02:44 +0200 schrieb Dawid Toton:
> Thanks for the very quick answer.
> Does it mean that I can render a module to be not applicative by adding
> a record type to it? This would break some existing code which relies on
> equality of some other types?
>
> On 2011-04-07 23:49, Gerd Stolpmann wrote:
> > Am Donnerstag, den 07.04.2011, 23:12 +0200 schrieb Dawid Toton:
> >> What does it mean that a functor is applicative?
> > Roughly: If you apply a functor twice with the same input modules, the
> > opaque types in the output remain compatible. For instance:
> >
> > module S1 = Set.Make(String)
> > module S2 = Set.Make(String)
> >
> > Now, S1.t and S2.t are type-compatible, although this type is opaque.
> > (E.g. you can do S1.empty = S2.empty.)
> But sometimes it doesn't work this way:
>
> module Make2(X : sig end) = struct type s end
> module M1 = Make2(struct end)
> module M2 = Make2(struct end)
> let g (a : M1.s) (b : M2.s) = a = b;;
>
> Error: This expression has type M2.s but an expression was expected of
> type M1.s
Because the input module is not the same. It relies on module paths to
check identities.
> > Compare this with:
> >
> > module Make(X : sig end) = struct type t = Variant end
> > module M1 = Make(struct end)
> > module M2 = Make(struct end)
My error. This is of course not the same effect.
> >
> > Now, M1.t and M2.t are incompatible - for nominal types like variants
> > the functors aren't applicative, and each instance is a thing of its
> > own:
> >
> > # M1.Variant = M2.Variant;;
> > Error: This expression has type M2.t but an expression was expected of
> > type M1.t
> >
> Honestly, I don't get it:
>
> module Make(X : sig end) = struct type t = Variant end
> module Empty = struct end
> module M1 = Make(Empty)
> module M2 = Make(Empty)
> ;;
> M1.Variant = M2.Variant
> ;;
>
> Toplevel responds with:
>
> module Make : functor (X : sig end) -> sig type t = Variant end
> module Empty : sig end
> module M1 : sig type t = Make(Empty).t = Variant end
> module M2 : sig type t = Make(Empty).t = Variant end
> # - : bool = true
>
> So I get applicative functor with a nominal type?
I think so. I remembered it the wrong way. There is a paper from XL
about this, see [5] in http://caml.inria.fr/about/papers.en.html.
Gerd
>
> >> Is there any analogy between applicative functors in OCaml and the
> >> Applicative type class of Haskell?
> I have some idea of it: we consider two types that play nicely together.
> I pass them through a functor. If the functor is applicative, the two
> resulting types also play nicely the same way as the original ones.
> Dawid
>
--
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany
gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de
Phone: +49-6151-153855 Fax: +49-6151-997714
------------------------------------------------------------
next prev parent reply other threads:[~2011-04-08 1:34 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-07 21:12 [Caml-list] " 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 [this message]
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
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=1302226479.8429.1154.camel@thinkpad \
--to=info@gerd-stolpmann.de \
--cc=caml-list@yquem.inria.fr \
--cc=d0@wp.pl \
/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).