-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
832 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.