Skip to content

Instantly share code, notes, and snippets.

View inrick's full-sized avatar

Fabian Carlström inrick

View GitHub Profile
(*
Example how OCaml's structurally typed modules can be combined and used. Note
the overlap of [return] in [APPLICATIVE] and [MONAD] and how the signatures
combine.
*)
let id x = x
module type FUNCTOR = sig
type 'a t
(** Modules sharing type constraint in functor. *)
module type MONOID = sig
type t
val op : t -> t -> t
val id : t
end
module type GROUP = sig
include MONOID
(* for OCaml <4.03.0 define:
type ('a, 'b) result = Ok of 'a | Error of 'b *)
module type MONAD = sig
type 'a t
val return : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
end
module Id = struct