-
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
9 changed files
with
157 additions
and
8 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ addons: | |
sources: | ||
- avsm | ||
packages: | ||
- aspcud | ||
- ocaml | ||
- opam | ||
- ocaml-native-compilers | ||
|
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.4.0 | ||
VERSION= 0.5.0 | ||
OFFICER= [email protected] | ||
|
||
.sinclude "Makefile.config" | ||
|
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,7 +1,7 @@ | ||
opam-version: "1.2" | ||
maintainer: "[email protected]" | ||
authors: "Michael Grünewald" | ||
version: "0.4.0" | ||
version: "0.5.0" | ||
license: "CeCILL-B" | ||
homepage: "https://github.com/michipili/lemonade" | ||
bug-reports: "https://github.com/michipili/lemonade/issues" | ||
|
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
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,92 @@ | ||
(* TestSuccessReader -- Test natural transformation | ||
Mixture (https://github.com/michipili/lemonade) | ||
This file is part of Lemonade | ||
Copyright © 2013–2016 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 *) | ||
|
||
open Format | ||
open Broken | ||
|
||
module Error = | ||
struct | ||
type t = string * string | ||
end | ||
|
||
module Success = | ||
Lemonade_Success.Make(Error) | ||
|
||
module Environment = | ||
struct | ||
type t = string | ||
end | ||
|
||
module Reader = | ||
Lemonade_Reader.Make(Environment) | ||
|
||
module Basis = | ||
Reader.T(Success) | ||
|
||
include Basis | ||
|
||
type 'a outcome = 'a Success.outcome = | ||
| Success of 'a | ||
| Error of Error.t | ||
|
||
let error err = | ||
Basis.lift(Success.error err) | ||
|
||
|
||
(* Lift operations from the success monad *) | ||
|
||
let run env m = | ||
Success.run(Basis.run env m) | ||
|
||
let recover m f = | ||
let g x = | ||
Success.return(f x) | ||
in | ||
let m' = | ||
Reader.bind m | ||
(fun s -> Reader.return(Success.recover (Success.map Basis.return s) g)) | ||
in | ||
Basis.join m' | ||
|
||
(* Pretty printing *) | ||
|
||
let pp_print_outcome_list_string pp m = | ||
let pp_print_list_string pp lst = | ||
Lemonade_List.pp_print pp_print_string pp lst | ||
in | ||
let pp_print_outcome f pp = | ||
function | ||
| Success(x) -> fprintf pp "Success(%a)" f x | ||
| Error(name, mesg) -> fprintf pp "Error(%S, %S)" name mesg | ||
in | ||
pp_print_outcome pp_print_list_string pp m | ||
|
||
let assert_outcome name env f expected = | ||
assert_equal ~printer:pp_print_outcome_list_string | ||
name (fun () -> run env f) () expected | ||
|
||
let () = | ||
register_suite "success_reader" | ||
"Test the Success Reader natural transformation" | ||
[ | ||
assert_outcome "prefix" | ||
"prefix" | ||
(Basis.access begin fun prefix -> [ prefix ^ "-a"; prefix ^ "-b"] end) | ||
(Success [ "prefix-a"; "prefix-b"]); | ||
|
||
assert_outcome "join" | ||
"join" | ||
(Basis.join (Basis.access begin | ||
fun prefix -> Reader.return(Success.return [ prefix ^ "-a" ]) end)) | ||
(Success ["join-a"]); | ||
] |