Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Dario Teixeira <darioteixeira@yahoo.com>
To: O Caml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] The "dummy" monad
Date: Fri, 3 Aug 2012 07:20:31 -0700 (PDT)	[thread overview]
Message-ID: <1344003631.53140.YahooMailNeo@web111509.mail.gq1.yahoo.com> (raw)

Hi,

I have a question about terminology.  Suppose I have a functor whose
implementation relies on a "get" function defined in the functor's parameter,
which is a module of type GETTER.  I want this functor to handle GETTER
implementations which may rely on the lightweight threads of Lwt.  The keyword
is "may", because I also want to allow GETTER implementations using another
monad other than Lwt's, or implementations not using any monad altogether.

To implement this I'm using a technique inspired by Jérôme Vouillon's
refactorisation of PG'OCaml to work in a monadic style.  Essentially,
I require any module implementing GETTER to define the monad it uses:

module type GETTER =
sig
    module Monad:
    sig
        type 'a t

        val return: 'a -> 'a t
        val fail: exn -> 'a t
        val bind: 'a t -> ('a -> 'b t) -> 'b t
        val catch: (unit -> 'a t) -> (exn -> 'a t) -> 'a t
    end

    val get: string -> string Monad.t
end


An implementation "Mygetter1" using Lwt can be defined as follows:

module Mygetter1: GETTER with type 'a Monad.t = 'a Lwt.t =
struct
    module Monad = Lwt

    let get x = ...
end


Whereas an implementation not requiring any special monad would be defined
as listed below, in essence defining a "dummy" monad.

module Mygetter2: GETTER with type 'a Monad.t = 'a =
struct
    module Monad =
    struct
        type 'a t = 'a

        let return x = x
        let fail x = raise x
        let bind t f = f t
        let catch t f = try t () with exc -> f exc
    end

    let get x = ...
end


Now, I suspect this is a well-known technique in monad-breathing circles.
But what is it called?  In particular, what should I be calling the "dummy"
monad?

Thanks in advance!
Best regards,
Dario Teixeira


             reply	other threads:[~2012-08-03 14:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-03 14:20 Dario Teixeira [this message]
2012-08-03 14:30 ` Jacques Carette

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=1344003631.53140.YahooMailNeo@web111509.mail.gq1.yahoo.com \
    --to=darioteixeira@yahoo.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