Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] concept style using first-class module
@ 2011-04-13  4:28 Satoshi Ogasawara
  2011-04-13  5:27 ` Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: Satoshi Ogasawara @ 2011-04-13  4:28 UTC (permalink / raw)
  To: caml-list

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-04-13  6:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-13  4:28 [Caml-list] concept style using first-class module Satoshi Ogasawara
2011-04-13  5:27 ` Jacques Garrigue
2011-04-13  6:01   ` Satoshi Ogasawara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox