Skip to content

Commit

Permalink
Lemonade 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
foretspaisibles committed Oct 10, 2015
2 parents 820e4f1 + c217184 commit 4107e28
Show file tree
Hide file tree
Showing 12 changed files with 832 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt

PACKAGE= lemonade
VERSION= 0.2.0
VERSION= 0.3.0
OFFICER= [email protected]

MODULE= ocaml.lib:src
Expand Down
8 changes: 8 additions & 0 deletions manual/intro.text
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
[Lemonade] provides standard monads as a library.

{!modules:
Lemonade_Continuation
Lemonade_Lazy
Lemonade_List
Lemonade_Maybe
Lemonade_Reader
Lemonade_State
Lemonade_Success
Lemonade_Writer
}

{!modules:
Lemonade_Type
}
7 changes: 4 additions & 3 deletions opam/opam
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bug-reports: "https://github.com/michipili/lemonade/issues"
dev-repo: "https://github.com/michipili/lemonade.git"
tags: [
"pattern"
"monad"
]
build: [
["./configure" "--prefix" prefix]
Expand All @@ -22,10 +23,10 @@ remove: [
["rm" "-rf" "%{share}%/doc/lemonade"]
]
depends: [
"ocamlfind"
"broken"
"broken" {>= "0.4.2"}
"bsdowl" {>= "3.0.0"}
"mixture"
"mixture"{>= "0.2.0"}
"ocamlfind"
]
depexts: [
[["debian"] ["bmake"]]
Expand Down
4 changes: 4 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
LIBRARY= lemonade

SRCS= lemonade_Type.ml
SRCS+= lemonade_Continuation.ml
SRCS+= lemonade_Lazy.ml
SRCS+= lemonade_List.ml
SRCS+= lemonade_Maybe.ml
SRCS+= lemonade_Reader.ml
SRCS+= lemonade_Retry.ml
SRCS+= lemonade_State.ml
SRCS+= lemonade_Success.ml
SRCS+= lemonade_Writer.ml

.include "ocaml.lib.mk"

Expand Down
50 changes: 50 additions & 0 deletions src/lemonade_Continuation.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
(* Lemonade_Continuation -- The continuation monad
Lemonade (https://github.com/michipili/lemonade)
This file is part of Lemonade
Copyright © 2013–2015 Michael Grünewald
This file must be used under the terms of the CeCILL-B.
This source file is licensed as described in the file COPYING, which
you should have received as part of this distribution. The terms
are also available at
http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt *)

module type FinalType =
sig
type t
end

module type S =
sig
type final
type 'a t = ('a -> final) -> final
include Lemonade_Type.S
with type 'a t := 'a t
val call_cc : (('a -> 'b t) -> 'a t) -> 'a t
end

module Make(Final:FinalType) =
struct
type final = Final.t
module Basis =
struct
type 'a t = ('a -> final) -> final

let return x =
fun cont -> cont x

let bind m f =
fun cont -> m (fun x -> (f x) cont)
end

module MethodsMonad =
Mixture_Monad.Make(Basis)

include Basis
include MethodsMonad

let call_cc kont =
fun cont -> kont (fun x -> (fun _ -> cont x)) cont
end
56 changes: 56 additions & 0 deletions src/lemonade_Continuation.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(* Lemonade_Continuation -- The continuation monad
Lemonade (https://github.com/michipili/lemonade)
This file is part of Lemonade
Copyright © 2013–2015 Michael Grünewald
This file must be used under the terms of the CeCILL-B.
This source file is licensed as described in the file COPYING, which
you should have received as part of this distribution. The terms
are also available at
http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt *)

(** Continuation monad.
The Continuation monad represents computations in
continuation-passing style (CPS). In continuation-passing style
function result is not returned, but instead is passed to another
function, received as a parameter (continuation). Computations are
built up from sequences of nested continuations, terminated by a
final continuation (often {i id}) which produces the final
result. Since continuations are functions which represent the
future of a computation, manipulation of the continuation
functions can achieve complex manipulations of the future of the
computation, such as interrupting a computation in the middle,
aborting a portion of a computation, restarting a computation, and
interleaving execution of computations. The Continuation monad
adapts CPS to the structure of a monad. *)


(** The input signature of the functor [Lemonade_Continuation.Make]. *)
module type FinalType =
sig
type t
end


(** The output signature of the functor [Lemonade_Continuation.Make]. *)
module type S =
sig
(** The final type. *)
type final

(** The type of continuations. *)
type 'a t = ('a -> final) -> final

include Lemonade_Type.S
with type 'a t := 'a t

val call_cc : (('a -> 'b t) -> 'a t) -> 'a t
(** Call with current continuation. *)
end

(** Functor building an implementation of the [Success] monad. *)
module Make(Final:FinalType):
S with type final = Final.t
100 changes: 100 additions & 0 deletions src/lemonade_Reader.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
(* Lemonade_Reader -- The classic reader monad
Lemonade (https://github.com/michipili/lemonade)
This file is part of Lemonade
Copyright © 2013–2015 Michael Grünewald
This file must be used under the terms of the CeCILL-B.
This source file is licensed as described in the file COPYING, which
you should have received as part of this distribution. The terms
are also available at
http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt *)

module type EnvironmentType =
sig
type t
end


module type S =
sig
type environment
include Lemonade_Type.S
val read : environment t
val run : environment -> 'a t -> 'a
val local : (environment -> environment) -> 'a t -> 'a t
val access : (environment -> 'a) -> 'a t
end


module Make(Environment:EnvironmentType) =
struct
type environment = Environment.t
module Basis =
struct
type 'a t =
environment -> 'a

let return x =
fun _ -> x

let bind m f =
fun env -> f (m env) env
end

module MethodsMonad =
Mixture_Monad.Make(Basis)

include Basis
include MethodsMonad

let read =
fun env -> env

let run env m =
m env

let local f m =
fun env -> m (f env)

let access f =
fun env -> f env


module T(M:Lemonade_Type.S) =
struct
type environment = Environment.t

module BasisT =
struct
type 'a t =
environment -> 'a M.t
let return x =
fun _ -> M.return x
let bind m f =
fun env -> M.bind (m env) (fun x -> f x env)
end

module MethodsMonadT =
Mixture_Monad.Make(BasisT)

include BasisT
include MethodsMonadT

let read =
fun env -> M.return env

let run env m =
m env

let local f m =
fun env -> m (f env)

let access f =
fun env -> M.return(f env)

let lift m =
fun _ -> m
end
end
80 changes: 80 additions & 0 deletions src/lemonade_Reader.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
(* Lemonade_Reader -- The classic reader monad
Lemonade (https://github.com/michipili/lemonade)
This file is part of Lemonade
Copyright © 2013–2015 Michael Grünewald
This file must be used under the terms of the CeCILL-B.
This source file is licensed as described in the file COPYING, which
you should have received as part of this distribution. The terms
are also available at
http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt *)

(** Reader monad.
Values in a {i Reader} monad or {i Environment monad} represent a
computation, which can read values from a shared environment, pass
values from function to function, and execute sub-computations in
a modified environment. Using a {i Reader} monad for such
computations is often clearer and easier than using a {i State}
monad. *)

(** The input signature of the functor [Lemonade_Reader.Make]. *)
module type EnvironmentType =
sig
type t
(** The type of data consumed in a reader monad. *)
end

(** The output signature of the functor [Lemonade_Reader.Make]. *)
module type S =
sig
type environment
(** The type of consumed data. *)

include Lemonade_Type.S

val read : environment t
(** Access the current environment. *)

val run : environment -> 'a t -> 'a
(** Perform a computation in the given environment errors. *)

val local : (environment -> environment) -> 'a t -> 'a t
(** Execute a computation in a modified environment. *)

val access : (environment -> 'a) -> 'a t
(** Access to a component of the current environment. *)

end

(** Functor building an implementation of the [Success] monad. *)
module Make(Environment:EnvironmentType):
sig
include S
with type environment = Environment.t

(** The success monad transformer. *)
module T(M:Lemonade_Type.S): sig
type environment = Environment.t
(** The type of consumed data. *)

include Lemonade_Type.S

val read : environment t
(** Access the current environment. *)

val run : environment -> 'a t -> 'a M.t
(** Perform a computation in the given environment errors. *)

val local : (environment -> environment) -> 'a t -> 'a t
(** Execute a computation in a modified environment. *)

val access : (environment -> 'a) -> 'a t
(** Access to a component of the current environment. *)

val lift : 'a M.t -> 'a t
(** Add an environment to a monad of type ['a M.t]. *)
end
end
Loading

0 comments on commit 4107e28

Please sign in to comment.