From: Leo White <lpw25@cam.ac.uk>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: OCaml mailing-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Locally abstract type with type parameters
Date: Sun, 24 Aug 2014 17:39:10 +0100 [thread overview]
Message-ID: <8738cl6dw1.fsf@study.localdomain> (raw)
In-Reply-To: <1408559896.43780.YahooMailNeo@web121705.mail.ne1.yahoo.com> (Dario Teixeira's message of "Wed, 20 Aug 2014 11:38:16 -0700")
Hi Dario,
> To avoid type-escaping-its-scope errors, we need to define a locally abstract
> type in the implementation of 'actually_process'. Something like this:
>
> let actually_process (type u) (module Logger: LOGGER with type 'a Monad.t = 'a u) x =
> let open Logger in
> let (>>=) t f = Monad.bind t f in
> Logger.log () >>= fun () ->
> Monad.return x
>
This function relies on higher-kinded polymorphism (i.e. it is
polymorphic in type `u` which has type parameters). Since OCaml's core
language does not provide direct support for higher-kinded polymorphism
the usual solution is to make `actually_process` into a functor. A
possible alternative solution, which may suit your use case, is outlined
in the paper "Lightweight higher-kinded polymorphism" [1] using the
"higher" library available on OPAM.
Regards,
Leo
[1] Lightweight higher-kinded polymorphism
Jeremy Yallop and Leo White FLOPS 2014
http://www.lpw25.net/flops2014.pdf
next prev parent reply other threads:[~2014-08-24 16:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-20 18:38 Dario Teixeira
2014-08-21 1:19 ` John F. Carr
2014-08-22 2:23 ` Benjamin Greenman
2014-08-24 16:39 ` Leo White [this message]
2014-08-26 14:33 ` Dario Teixeira
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=8738cl6dw1.fsf@study.localdomain \
--to=lpw25@cam.ac.uk \
--cc=caml-list@inria.fr \
--cc=darioteixeira@yahoo.com \
/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