Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Satoshi Ogasawara <ogasawara@itpl.co.jp>
To: caml-list <caml-list@yquem.inria.fr>
Subject: [Caml-list] concept style using first-class module
Date: Wed, 13 Apr 2011 13:28:54 +0900	[thread overview]
Message-ID: <4DA52686.40200@itpl.co.jp> (raw)

Hello,

Recently I learned concept style generic programming like Haskell type-class.
I'd like to emulate that style in OCaml using first-class modules.

e.g.

module type Monad = sig
  type 'a t
  val return : 'a -> 'a t
  val bind : 'a t -> ('a -> 'b t) -> 'b t
end

module type MonadPlus = sig
  type 'a t
  include Monad with type 'a t := 'a t
  val zero : 'a t
  val plus : 'a t -> 'a t -> 'a t
end

let foo (module M:MonadPlus) m = M.bind m (fun x -> M.return x)

But above code makes an error at the last line.

  Error: This `let module' expression has type 'a M.t -> 'a M.t
  In this type, the locally bound module name M escapes its scope

I have tried to add a (type s) parameter and specialize module
types but It's not work.

How can I make this code typable? Is it impossible without higher
order type operator?

Regards,
  ogasawara

             reply	other threads:[~2011-04-13  4:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-13  4:28 Satoshi Ogasawara [this message]
2011-04-13  5:27 ` Jacques Garrigue
2011-04-13  6:01   ` Satoshi Ogasawara

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=4DA52686.40200@itpl.co.jp \
    --to=ogasawara@itpl.co.jp \
    --cc=caml-list@yquem.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