Skip to content

Commit

Permalink
Lemonade 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
foretspaisibles committed Aug 20, 2015
2 parents 14382df + dda8634 commit 820e4f1
Show file tree
Hide file tree
Showing 26 changed files with 906 additions and 35 deletions.
8 changes: 8 additions & 0 deletions .travis.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
compiler:
- 4.01.0
- 4.02.3
repository:
- ocamlfind
git:
- https://github.com/michipili/broken.git
- https://github.com/michipili/mixture.git
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: c
sudo: false
addons:
apt:
sources:
- avsm
packages:
- ocaml
- opam
- ocaml-native-compilers
install: sh -ex ./Library/Ancillary/autoinstall bmake bsdowl opam
script: sh -ex ./Library/Ancillary/travisci
cache:
directories:
- ${HOME}/.local
- ${HOME}/.opam
env:
- TRAVIS_OCAML_VERSION=4.01.0
- TRAVIS_OCAML_VERSION=4.02.3
25 changes: 25 additions & 0 deletions Library/Ancillary/autoinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

### autoinstall -- Autoinstall for Travis CI

# Lemonade (https://github.com/michipili/lemonade)
# This file is part of Lemonade
#
# Copyright © 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

: ${local:=${HOME}/.local}
: ${srcdir:=${HOME}/.local/sources}

if [ -f "${local}/.anvil_autoinstall_cached" ]; then exit 0; fi

git clone 'https://github.com/michipili/anvil' "${srcdir}/anvil"
/bin/sh -ex "${srcdir}/anvil/subr/anvil_travisci_autoinstall.sh" "$@"\
&& touch "${local}/.anvil_autoinstall_cached"

### End of file `autoinstall'
23 changes: 23 additions & 0 deletions Library/Ancillary/travisci
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

### travisci -- Continuous integration test for travis

# Lemonade (https://github.com/michipili/lemonade)
# This file is part of Lemonade
#
# Copyright © 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

INSTALL_PREFIX="${HOME}/.local"

eval $(opam config env)
autoconf
./configure --prefix="${INSTALL_PREFIX}"
bmake -I "${INSTALL_PREFIX}/share/bsdowl" all

### End of file `travisci'
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt

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

MODULE= ocaml.lib:src
MODULE+= ocaml.meta:meta
MODULE+= ocaml.manual:manual

EXTERNAL= ocaml.findlib:mixture
SUBDIR= testsuite

EXTERNAL= ocaml.findlib:broken
EXTERNAL+= ocaml.findlib:mixture

CONFIGURE+= Makefile.config.in

Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Lemonade, the sparkling monad library

The **Lemonade** project aims at providing a comprehensive monad
library for OCaml module system.
The **Lemonade** project aims at providing a comprehensive standard
monad library for OCaml.

[![Build Status](https://travis-ci.org/michipili/lemonade.svg?branch=master)](https://travis-ci.org/michipili/lemonade?branch=master)

It implements the following monads:

- `Lemonade_Lazy`
- `Lemonade_List`
- `Lemonade_Maybe`
- `Lemonade_Success`
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ AC_CONFIG_MACRO_DIR([Library/Autoconf])
AC_NEED_OCAML
AC_NEED_FINDLIB
AC_NEED_FINDLIB_PKG([mixture])
AC_NEED_FINDLIB_PKG([broken])
AC_WITH_OCAML_SITE_LIB
AC_CONFIG_FILES([Makefile.config])
AC_OUTPUT
Expand Down
1 change: 1 addition & 0 deletions meta/lemonade.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name="lemonade"
version="@VERSION@"
description="Monad library with bubbles"
requires="mixture"
archive(byte) = "lemonade.cma"
archive(native) = "lemonade.cmxa"
6 changes: 4 additions & 2 deletions opam/opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ install: [
["make" "-I%{bsdowl:share}%" "install"] {os = "freebsd"}
]
remove: [
["ocamlfind" "remove" "mixture"]
["rm" "-rf" "%{share}%/doc/mixture"]
["ocamlfind" "remove" "lemonade"]
["rm" "-rf" "%{share}%/doc/lemonade"]
]
depends: [
"ocamlfind"
"broken"
"bsdowl" {>= "3.0.0"}
"mixture"
]
depexts: [
[["debian"] ["bmake"]]
Expand Down
6 changes: 4 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
# are also available at
# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt

LIBRARY= mixture
LIBRARY= lemonade

SRCS= lemonade_Lazy.ml
SRCS= lemonade_Type.ml
SRCS+= lemonade_Lazy.ml
SRCS+= lemonade_List.ml
SRCS+= lemonade_Maybe.ml
SRCS+= lemonade_Retry.ml
SRCS+= lemonade_Success.ml

.include "ocaml.lib.mk"
Expand Down
36 changes: 34 additions & 2 deletions src/lemonade_Lazy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,46 @@ struct
'a Lazy.t

let bind m f =
f (Lazy.force m)
lazy (Lazy.force (f (Lazy.force m)))

let return x =
lazy x

end

module MethodsMonad = Mixture_Monad.Make(Basis)
module MethodsMonad =
Mixture_Monad.Make(Basis)

include Basis
include MethodsMonad

let exec m =
Lazy.force m

let pp_print f pp m =
let open Format in
if Lazy.is_val m then
fprintf pp "Lazy(%a)" f (Lazy.force m)
else
fprintf pp "Lazy(<deferred>)"


module T(M:Mixture_Monad.S) =
struct

module Germ =
struct

type 'a t =
'a Lazy.t M.t

let bind m f =
M.bind m (fun x -> (f (Lazy.force x)))

let return x =
M.return(lazy x)

end

include Mixture_Monad.Transformer.Make(Basis)(M)(Germ)
end
17 changes: 16 additions & 1 deletion src/lemonade_Lazy.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,20 @@
type (+'a) t =
'a Lazy.t

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

(** Execute the computation. *)
val exec : 'a t -> 'a

val pp_print : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a Lazy.t -> unit
(** A generic printer for lazy values. *)

(** The lazy monad transformer. *)
module T(M:Lemonade_Type.S) :
sig
include Lemonade_Type.S
with type 'a t = 'a Lazy.t M.t

val lift : 'a M.t -> 'a t
end
32 changes: 32 additions & 0 deletions src/lemonade_List.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,35 @@ module MethodsMonad = Mixture_Monad.Make(Basis)

include Basis
include MethodsMonad

let pp_print f pp m =
let open Format in
let sep = ref "" in
fprintf pp "[";
List.iter (fun x -> fprintf pp "%s%a" (!sep) f x; sep := "; ") m;
fprintf pp "]"


module T(M:Mixture_Monad.S) =
struct

module Germ =
struct

type 'a t =
'a list M.t

let bind m f =
M.bind m
(fun lst ->
(List.map f lst)
|> M.dist
|> (M.map List.concat))

let return x =
M.return([x])

end

include Mixture_Monad.Transformer.Make(Basis)(M)(Germ)
end
14 changes: 13 additions & 1 deletion src/lemonade_List.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,17 @@
type (+'a) t =
'a list

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

val pp_print : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a list -> unit
(** A generic printer for list values. *)

(** The list monad transformer. *)
module T(M:Lemonade_Type.S) :
sig
include Lemonade_Type.S
with type 'a t = 'a list M.t

val lift : 'a M.t -> 'a t
end
67 changes: 66 additions & 1 deletion src/lemonade_Maybe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,72 @@ struct

end

module MethodsMonad = Mixture_Monad.Make(Basis)
let pp_print f pp m =
let open Format in
match m with
| Some(x) -> fprintf pp "Some(%a)" f x
| None -> fprintf pp "None"

let is_some = function
| Some(_) -> true
| None -> false

let is_none = function
| Some(_) -> false
| None -> true

let find = function
| Some(b) -> b
| None -> raise Not_found

let default a = function
| Some(b) -> b
| None -> a

let of_list = function
| [] -> None
| a :: _ -> Some(a)

let to_list = function
| Some(a) -> [a]
| None -> []

let filter_map f lst =
List.fold_left
(fun acc x -> match f x with
| Some(a) -> a :: acc
| None -> acc) [] lst
|> List.rev

let filter lst =
filter_map (fun x -> x) lst

module MethodsMonad =
Mixture_Monad.Make(Basis)

include Basis
include MethodsMonad

module T(M:Mixture_Monad.S) =
struct

module Germ =
struct

type 'a t =
'a option M.t

let bind m f =
M.bind m
(function
| None -> M.return None
| Some(x) -> f x)

let return x =
M.return(Some(x))

end


include Mixture_Monad.Transformer.Make(Basis)(M)(Germ)
end
Loading

0 comments on commit 820e4f1

Please sign in to comment.