From 84cf2cc7757b1cc5370a61c7e5cda62ec09e8776 Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Mon, 30 Mar 2020 10:53:33 +0200 Subject: [PATCH] Obey horizontal space restrictions in Reason snippets. --- src/content/1.1/code/reason/snippet03.re | 2 +- src/content/1.10/code/reason/snippet09.re | 3 ++- src/content/1.10/code/reason/snippet12.re | 3 ++- src/content/1.5/code/reason/snippet10.re | 5 +++- src/content/1.6/code/reason/snippet20.re | 2 +- src/content/1.7/code/reason/snippet28.re | 3 ++- src/content/1.8/code/reason/snippet01.re | 3 ++- src/content/1.8/code/reason/snippet03.re | 3 ++- src/content/1.8/code/reason/snippet08.re | 4 ++-- src/content/1.8/code/reason/snippet09.re | 5 +++- src/content/1.8/code/reason/snippet13.re | 3 ++- src/content/1.8/code/reason/snippet14.re | 4 +++- src/content/1.9/code/reason/snippet11.re | 2 +- src/content/2.2/code/reason/snippet02.re | 3 ++- src/content/2.2/code/reason/snippet06.re | 2 +- src/content/2.2/code/reason/snippet09.re | 2 +- src/content/2.3/code/reason/snippet02.re | 4 ++-- src/content/3.10/code/reason/snippet04.re | 1 - src/content/3.10/code/reason/snippet09.re | 4 ++-- src/content/3.10/code/reason/snippet12.re | 15 ++++++------ src/content/3.10/code/reason/snippet16.re | 9 ++++--- src/content/3.11/code/reason/snippet05.re | 29 ++++++++++------------- src/content/3.11/code/reason/snippet07.re | 4 +++- src/content/3.11/code/reason/snippet08.re | 13 +++++----- src/content/3.11/code/reason/snippet10.re | 10 ++++---- src/content/3.11/code/reason/snippet12.re | 5 ++-- src/content/3.2/code/reason/snippet06.re | 9 +++---- src/content/3.4/code/reason/snippet01.re | 3 ++- src/content/3.4/code/reason/snippet02.re | 5 ++-- src/content/3.4/code/reason/snippet05.re | 3 ++- src/content/3.4/code/reason/snippet17.re | 3 ++- src/content/3.4/code/reason/snippet18.re | 5 ++-- src/content/3.4/code/reason/snippet22.re | 5 ++-- src/content/3.5/code/reason/snippet03.re | 2 +- src/content/3.5/code/reason/snippet05.re | 2 +- src/content/3.5/code/reason/snippet12.re | 3 ++- src/content/3.5/code/reason/snippet25.re | 6 ++--- src/content/3.5/code/reason/snippet37.re | 2 +- src/content/3.6/code/reason/snippet21.re | 12 ++++------ src/content/3.7/code/reason/snippet15.re | 3 ++- src/content/3.7/code/reason/snippet20.re | 3 ++- src/content/3.8/code/reason/snippet04.re | 8 ++----- src/content/3.8/code/reason/snippet06.re | 3 +-- src/content/3.8/code/reason/snippet26.re | 5 ++-- src/content/3.8/code/reason/snippet28.re | 7 ++---- src/content/3.8/code/reason/snippet29.re | 7 ++---- src/content/3.8/code/reason/snippet31.re | 3 ++- src/content/3.9/code/reason/snippet03.re | 1 - src/content/3.9/code/reason/snippet09.re | 5 ++-- 49 files changed, 123 insertions(+), 125 deletions(-) diff --git a/src/content/1.1/code/reason/snippet03.re b/src/content/1.1/code/reason/snippet03.re index 95783e7d..cc558d05 100644 --- a/src/content/1.1/code/reason/snippet03.re +++ b/src/content/1.1/code/reason/snippet03.re @@ -3,7 +3,7 @@ module Compose_Example = F: Polymorphic_Function_F, G: Polymorphic_Function_G with type b = F.b, ) => { - /** ReasonML/OCaml doesn't have a compose operator. So, creating one. **/ + /** ReasonML doesn't have a compose operator. So, creating one. **/ let (>>) = (g, f, x) => g(f(x)); let compose: 'a => 'c = (G.g >> F.f: 'a => 'c); diff --git a/src/content/1.10/code/reason/snippet09.re b/src/content/1.10/code/reason/snippet09.re index 61634988..348cc629 100644 --- a/src/content/1.10/code/reason/snippet09.re +++ b/src/content/1.10/code/reason/snippet09.re @@ -1 +1,2 @@ -let safe_head = (fmap([x, ...xs])) == safe_head(f([x, ... xs])) == Some(f(x)); \ No newline at end of file +let safe_head = + (fmap([x, ...xs])) == safe_head(f([x, ... xs])) == Some(f(x)); \ No newline at end of file diff --git a/src/content/1.10/code/reason/snippet12.re b/src/content/1.10/code/reason/snippet12.re index dfcf270f..2afb461a 100644 --- a/src/content/1.10/code/reason/snippet12.re +++ b/src/content/1.10/code/reason/snippet12.re @@ -1,4 +1,5 @@ -/* ReasonML/OCaml requires mutually recursive functions to be defined together */ +/* ReasonML requires mutually recursive functions +* to be defined together */ let rec length: list('a) => const(int, 'a) = ( fun | [] => Const(0) diff --git a/src/content/1.5/code/reason/snippet10.re b/src/content/1.5/code/reason/snippet10.re index c773f25f..65662e52 100644 --- a/src/content/1.5/code/reason/snippet10.re +++ b/src/content/1.5/code/reason/snippet10.re @@ -1,5 +1,8 @@ module Chapter5_Product_Example: - Chapter5_Product with type a = int and type b = bool and type c = int = { + Chapter5_Product + with type a = int + and type b = bool + and type c = int = { type a = int; type b = bool; type c = int; diff --git a/src/content/1.6/code/reason/snippet20.re b/src/content/1.6/code/reason/snippet20.re index 982e4ab9..16544a5a 100644 --- a/src/content/1.6/code/reason/snippet20.re +++ b/src/content/1.6/code/reason/snippet20.re @@ -1,2 +1,2 @@ -// ReasonML/OCaml only allows special characters in the infix operator. +// ReasonML only allows special characters in the infix operator. // So, the above function name cannot be applied as infix. diff --git a/src/content/1.7/code/reason/snippet28.re b/src/content/1.7/code/reason/snippet28.re index 1416ba0a..e6a49a84 100644 --- a/src/content/1.7/code/reason/snippet28.re +++ b/src/content/1.7/code/reason/snippet28.re @@ -1,5 +1,6 @@ module Const_Functor = (T: T) : Functor => { type t('a) = const(T.t, 'a); - let fmap = (f, Const(c)) => Const(c); /* or even let fmap = (_ c) => c */ + // or even let fmap = (_, c) => c; + let fmap = (f, Const(c)) => Const(c); }; diff --git a/src/content/1.8/code/reason/snippet01.re b/src/content/1.8/code/reason/snippet01.re index 7a4be81b..79fd602a 100644 --- a/src/content/1.8/code/reason/snippet01.re +++ b/src/content/1.8/code/reason/snippet01.re @@ -1,4 +1,5 @@ -/** You can represent bifunctor defintion in two forms and implement just and derive the other from it. */ +/** You can represent bifunctor defintion in two forms + * and implement just and derive the other from it. */ module type BifunctorCore = { type t('a, 'b); diff --git a/src/content/1.8/code/reason/snippet03.re b/src/content/1.8/code/reason/snippet03.re index a029e7d0..5570a882 100644 --- a/src/content/1.8/code/reason/snippet03.re +++ b/src/content/1.8/code/reason/snippet03.re @@ -1 +1,2 @@ -let bimap: ('a => 'c, 'b => 'd, Bifunctor_Product.t('a, 'b)) => Bifunctor_Product.t('c, 'd) \ No newline at end of file +let bimap: ('a => 'c, 'b => 'd, Bifunctor_Product.t('a, 'b)) => + Bifunctor_Product.t('c, 'd) \ No newline at end of file diff --git a/src/content/1.8/code/reason/snippet08.re b/src/content/1.8/code/reason/snippet08.re index ce21790e..d5ed628a 100644 --- a/src/content/1.8/code/reason/snippet08.re +++ b/src/content/1.8/code/reason/snippet08.re @@ -1,8 +1,8 @@ -/* ReasonML/OCaml doesn't have a built in Const type */ +/* ReasonML doesn't have a built in Const type */ type const('a, 'b) = | Const('a); -/* ReasonML/OCaml doesn't have a built in either type */ +/* ReasonML doesn't have a built in either type */ type either('a, 'b) = | Left('a) | Right('b); diff --git a/src/content/1.8/code/reason/snippet09.re b/src/content/1.8/code/reason/snippet09.re index 7fbd5d3a..2aed101e 100644 --- a/src/content/1.8/code/reason/snippet09.re +++ b/src/content/1.8/code/reason/snippet09.re @@ -1,4 +1,7 @@ -/** ReasonML/OCaml doesn't support higher kinded types. So, we have to use module functors to emulate the behavior higher kinded types. There's less verbose options using type defunctionalization but it's more advanced and obscures the flow of this book */ +/** ReasonML doesn't support higher kinded types. + * So, we have to use module functors to emulate the behavior higher kinded types. + * There's less verbose options using type defunctionalization + * but it's more advanced and obscures the flow of this book */ module type BiComp = ( BF: {type t('a, 'b);}, diff --git a/src/content/1.8/code/reason/snippet13.re b/src/content/1.8/code/reason/snippet13.re index 25fe9f0a..f2796a2c 100644 --- a/src/content/1.8/code/reason/snippet13.re +++ b/src/content/1.8/code/reason/snippet13.re @@ -1 +1,2 @@ -let bimap: (FU.t(a) => FU.t(a')) => (GU.t(b) => GU.t(b')) => (FU.t(a), GU.t(b)) => (FU.t(a'), GU.t(b')) \ No newline at end of file +let bimap: (FU.t(a) => FU.t(a')) => (GU.t(b) => GU.t(b')) => + (FU.t(a), GU.t(b)) => (FU.t(a'), GU.t(b')) \ No newline at end of file diff --git a/src/content/1.8/code/reason/snippet14.re b/src/content/1.8/code/reason/snippet14.re index 48aebeb0..158f88ce 100644 --- a/src/content/1.8/code/reason/snippet14.re +++ b/src/content/1.8/code/reason/snippet14.re @@ -1,4 +1,6 @@ -/** Deriving a functor in ReasonML/OCaml is not available as a language extension. You could try experimental library like ocsigen to derive functors.*/ +/** Deriving a functor in ReasonML is not available as a + * language extension. You could try experimental library + * like ocsigen to derive functors.*/ type tree('a) = | Leaf('a) | Node(tree('a), tree('a)); diff --git a/src/content/1.9/code/reason/snippet11.re b/src/content/1.9/code/reason/snippet11.re index e8681870..d3794b60 100644 --- a/src/content/1.9/code/reason/snippet11.re +++ b/src/content/1.9/code/reason/snippet11.re @@ -2,5 +2,5 @@ module Exp_Sum_Impl: Exponential_Of_Sums_Example = { let f = fun | Left(n) => n < 0 ? "Negative int" : "Positive int" - | Right(x) => Float.compare(x, 0.4) < 0 ? "Negative double" : "Positive double" + | Right(x) => x < 0.0 ? "Negative double" : "Positive double" }; diff --git a/src/content/2.2/code/reason/snippet02.re b/src/content/2.2/code/reason/snippet02.re index 25b548b6..a7a15077 100644 --- a/src/content/2.2/code/reason/snippet02.re +++ b/src/content/2.2/code/reason/snippet02.re @@ -1,3 +1,4 @@ let contramap: ('c_prime => 'c, 'c => 'limD, 'c_prime) => 'limD = ( - (f, u) => compose(u, f): ('c_prime => 'c, 'c => 'limD, 'c_prime) => 'limD + (f, u) => compose(u, f): + ('c_prime => 'c, 'c => 'limD, 'c_prime) => 'limD ); diff --git a/src/content/2.2/code/reason/snippet06.re b/src/content/2.2/code/reason/snippet06.re index 1373f195..36f01bad 100644 --- a/src/content/2.2/code/reason/snippet06.re +++ b/src/content/2.2/code/reason/snippet06.re @@ -1,2 +1,2 @@ -/* Pseudo ReasonML/OCaml expressing function equality */ +/* Pseudo ReasonML expressing function equality */ compose(f, p) == compose(g, p); diff --git a/src/content/2.2/code/reason/snippet09.re b/src/content/2.2/code/reason/snippet09.re index ff012af2..1e4b6b8c 100644 --- a/src/content/2.2/code/reason/snippet09.re +++ b/src/content/2.2/code/reason/snippet09.re @@ -1,2 +1,2 @@ -/* Pseudo ReasonML/OCaml expressing function equality */ +/* Pseudo ReasonML expressing function equality */ compose(f, p') == compose(g, p'); diff --git a/src/content/2.3/code/reason/snippet02.re b/src/content/2.3/code/reason/snippet02.re index ff5eb758..12c55468 100644 --- a/src/content/2.3/code/reason/snippet02.re +++ b/src/content/2.3/code/reason/snippet02.re @@ -1,5 +1,5 @@ -module ListMonoid = (T1: {type a;}): - (Monoid with type m = list(T1.a)) => { +module ListMonoid = (T1: {type a;}) : + (Monoid with type m = list(T1.a)) => { type m = list(T1.a); let mempty = []; diff --git a/src/content/3.10/code/reason/snippet04.re b/src/content/3.10/code/reason/snippet04.re index 032fb001..05d80559 100644 --- a/src/content/3.10/code/reason/snippet04.re +++ b/src/content/3.10/code/reason/snippet04.re @@ -1,3 +1,2 @@ /* There is no compose operator in ReasonML */ - compose(dimap(id, f), alpha) == compose(dimap(f, id), alpha); diff --git a/src/content/3.10/code/reason/snippet09.re b/src/content/3.10/code/reason/snippet09.re index 895c7bab..3afb3b62 100644 --- a/src/content/3.10/code/reason/snippet09.re +++ b/src/content/3.10/code/reason/snippet09.re @@ -1,9 +1,9 @@ module EndsEqualizer = (P: Profunctor) => { let lambda: (P.p('a, 'a), 'a => 'b) => P.p('a, 'b) = ( - (paa, f) => P.dimap(id, f, paa): (P.p('a, 'a), 'a => 'b) => P.p('a, 'b) + (paa, f) => P.dimap(id, f, paa) ); let rho: (P.p('b, 'b), 'a => 'b) => P.p('a, 'b) = ( - (pbb, f) => P.dimap(f, id, pbb): (P.p('b, 'b), 'a => 'b) => P.p('a, 'b) + (pbb, f) => P.dimap(f, id, pbb) ); }; diff --git a/src/content/3.10/code/reason/snippet12.re b/src/content/3.10/code/reason/snippet12.re index 46baac77..12a1280f 100644 --- a/src/content/3.10/code/reason/snippet12.re +++ b/src/content/3.10/code/reason/snippet12.re @@ -1,16 +1,15 @@ -module EndsWithDiaProd = - ( - P: Profunctor, - D: DiaProd with type p('a, 'b) = P.p('a, 'b), - PP: ProdP with type p('a, 'b) = P.p('a, 'b), - ) => { +module EndsWithDiaProd = ( + P: Profunctor, + D: DiaProd with type p('a, 'b) = P.p('a, 'b), + PP: ProdP with type p('a, 'b) = P.p('a, 'b), + ) => { module E = EndsEqualizer(P); let lambdaP: D.diaprod('a) => PP.prod_p('a, 'b) = ( - (DiaProd(paa)) => E.lambda(paa): D.diaprod('a) => PP.prod_p('a, 'b) + (DiaProd(paa)) => E.lambda(paa) ); let rhoP: D.diaprod('b) => PP.prod_p('a, 'b) = ( - (DiaProd(pbb)) => E.rho(pbb): D.diaprod('b) => PP.prod_p('a, 'b) + (DiaProd(pbb)) => E.rho(pbb) ); }; diff --git a/src/content/3.10/code/reason/snippet16.re b/src/content/3.10/code/reason/snippet16.re index 50b27154..6e5ac250 100644 --- a/src/content/3.10/code/reason/snippet16.re +++ b/src/content/3.10/code/reason/snippet16.re @@ -10,11 +10,11 @@ module CoEndImpl = (P: Profunctor) => { type b; module type Sum_P = - SumP with type p('a, 'b) = P.p('a, 'b) and type a = a and type b = b; + SumP with type p('a, 'b) = P.p('a, 'b) + and type a = a and type b = b; let lambda = (module S: Sum_P): (module DiagSum) => - (module - { + (module { type a = S.b; type p('a, 'b) = P.p('a, 'b); @@ -22,8 +22,7 @@ module CoEndImpl = (P: Profunctor) => { }); let rho = (module S: Sum_P): (module DiagSum) => - (module - { + (module { type a = S.a; type p('a, 'b) = P.p('a, 'b); diff --git a/src/content/3.11/code/reason/snippet05.re b/src/content/3.11/code/reason/snippet05.re index 32125759..06fe9ac4 100644 --- a/src/content/3.11/code/reason/snippet05.re +++ b/src/content/3.11/code/reason/snippet05.re @@ -2,26 +2,21 @@ let fold_map = (type i, module M: Monoid with type m = i, xs, f) => List.fold_left((acc, a) => M.mappend(acc, f(a)), M.mempty, xs); let to_lst = (type x, xs: list(x)) => { - module LM: Monoid with type m = list(x) = - ListMonoid({ - type a = x; - }); + module LM: Monoid with type m = list(x) = + ListMonoid({type a = x;}); - ( - (module - { - type a = x; - type m = list(x); + (module { + type a = x; + type m = list(x); - module M = LM; + module M = LM; - type lst = (a => LM.m) => LM.m; + type lst = (a => LM.m) => LM.m; - let f = g => fold_map((module LM), xs, g); - }): (module Lst with type a = x) - ); + let f = g => fold_map((module LM), xs, g); + }); }; -let from_lst = - (type x, module LstImpl: Lst with type a = x and type m = list(x)) => - LstImpl.f(x => [x]); +let from_lst = (type x, + module LstImpl: Lst with type a = x and type m = list(x) + ) => LstImpl.f(x => [x]); diff --git a/src/content/3.11/code/reason/snippet07.re b/src/content/3.11/code/reason/snippet07.re index d8d05843..ab90f304 100644 --- a/src/content/3.11/code/reason/snippet07.re +++ b/src/content/3.11/code/reason/snippet07.re @@ -6,5 +6,7 @@ module type Exp = { type k('a) = ('a, a); include - Lan with type k('a) := (a, 'a) and type d('a) := d('a) and type a := b; + Lan with type k('a) := (a, 'a) + and type d('a) := d('a) + and type a := b; }; diff --git a/src/content/3.11/code/reason/snippet08.re b/src/content/3.11/code/reason/snippet08.re index 3cf93c3c..77ad9d4f 100644 --- a/src/content/3.11/code/reason/snippet08.re +++ b/src/content/3.11/code/reason/snippet08.re @@ -1,7 +1,6 @@ -let to_exp = - (type a', type b', f): (module Exp with type a = a' and type b = b') => - (module - { +let to_exp = (type a', type b', f) : + (module Exp with type a = a' and type b = b') => + (module { type a = a'; type b = b'; type d('a) = @@ -11,10 +10,10 @@ let to_exp = let fk = ((a, _)) => f(a); let di = I(); - }); + }); -let from_exp = - (type a', type b', module E: Exp with type a = a' and type b = b', a) => { +let from_exp = (type a', type b', + module E: Exp with type a = a' and type b = b', a) => { let I(i) = E.di; E.fk((a, i)); }; diff --git a/src/content/3.11/code/reason/snippet10.re b/src/content/3.11/code/reason/snippet10.re index 5d6dd99c..66ad80a8 100644 --- a/src/content/3.11/code/reason/snippet10.re +++ b/src/content/3.11/code/reason/snippet10.re @@ -4,15 +4,15 @@ module FreeFunctor = (F: {type f('a);}) : Functor => { type t('a) = (module F with type a = 'a); let fmap = - (type a', type b', f: a' => b', module FF: F with type a = a') - : (module F with type a = b') => - (module - { + (type a', type b', + f: a' => b', module FF: F with type a = a') : + (module F with type a = b') => + (module { type f('a) = F.f('a); type a = b'; type i = FF.i; let h = i => f(FF.h(i)); let fi = FF.fi; - }); + }); }; diff --git a/src/content/3.11/code/reason/snippet12.re b/src/content/3.11/code/reason/snippet12.re index 0ce8401f..97c9ff13 100644 --- a/src/content/3.11/code/reason/snippet12.re +++ b/src/content/3.11/code/reason/snippet12.re @@ -6,11 +6,10 @@ module FreeFunctorAlt = (F: {type f('a);}) : Functor => { let fmap = (type a', type b', f, module FF: F with type a = a') : (module F with type a = b') => - (module - { + (module { type a = b'; type f('a) = F.f('a); let freeF = bi => FF.freeF(a => bi(f(a))); - }); + }); }; diff --git a/src/content/3.2/code/reason/snippet06.re b/src/content/3.2/code/reason/snippet06.re index 21eda02a..f4dee851 100644 --- a/src/content/3.2/code/reason/snippet06.re +++ b/src/content/3.2/code/reason/snippet06.re @@ -1,4 +1,5 @@ -/* Putting it all together to show the equivalence between unit/counit and left_adjunct/right_adjunct */ +/* Putting it all together to show the equivalence between +* unit & counit and left_adjunct & right_adjunct */ module type Adjunction = (F: Functor, U: Representable) => { let unit: 'a => U.t(F.t('a)); @@ -7,7 +8,7 @@ module type Adjunction = let right_adjunct: ('a => U.t('b), F.t('a)) => 'b; }; -/* Adjunction via unit/counit */ +/* Adjunction via unit & counit */ module type Adjunction_Unit_Counit = (F: Functor, U: Representable) => { let unit: 'a => U.t(F.t('a)); @@ -21,7 +22,7 @@ module type Adjunction_Hom_Set = let right_adjunct: ('a => U.t('b), F.t('a)) => 'b; }; -/* Implementing unit/counit from left and right adjoint definitions */ +/* Implementing unit & counit from left and right adjoint definitions */ module Adjunction_From_Hom_Set = (A: Adjunction_Hom_Set) : Adjunction => (F: Functor, U: Representable) => { type f('t) = F.t('t); @@ -34,7 +35,7 @@ module Adjunction_From_Hom_Set = (A: Adjunction_Hom_Set) : Adjunction => let counit: 'a. f(u('a)) => 'a = fua => M.right_adjunct(idty, fua); }; -/* Implementing left and right adjunct from unit/counit Definitions */ +/* Implementing left and right adjunct from unit & counit Definitions */ module Adjunction_From_Unit_Counit = (A: Adjunction_Unit_Counit) : Adjunction => (F: Functor, U: Representable) => { type f('t) = F.t('t); diff --git a/src/content/3.4/code/reason/snippet01.re b/src/content/3.4/code/reason/snippet01.re index e9c0f67f..d0d96e9a 100644 --- a/src/content/3.4/code/reason/snippet01.re +++ b/src/content/3.4/code/reason/snippet01.re @@ -1,6 +1,7 @@ /* Depends on OCaml library Core */ module Vlen = (F: Functor with type t('a) = list('a)) => { - let summable: module Base__.Container_intf.Summable with type t = float = + let summable: + module Base__.Container_intf.Summable with type t = float = (module Float); let vlen = diff --git a/src/content/3.4/code/reason/snippet02.re b/src/content/3.4/code/reason/snippet02.re index 2623a20a..f50b8be2 100644 --- a/src/content/3.4/code/reason/snippet02.re +++ b/src/content/3.4/code/reason/snippet02.re @@ -1,6 +1,5 @@ -module WriterInstance = - (W: {type w;}) - : (Functor with type t('a) = writer(W.w, 'a)) => { +module WriterInstance = (W: {type w;}) : + (Functor with type t('a) = writer(W.w, 'a)) => { type t('a) = writer(W.w, 'a); let fmap = (f, Writer(a, w)) => Writer(f(a), w); diff --git a/src/content/3.4/code/reason/snippet05.re b/src/content/3.4/code/reason/snippet05.re index bdec037d..0136b07a 100644 --- a/src/content/3.4/code/reason/snippet05.re +++ b/src/content/3.4/code/reason/snippet05.re @@ -1,4 +1,5 @@ -module WriterMonad = (W: Monoid) : (Monad with type m('a) = writer(W.a, 'a)) => { +module WriterMonad = (W: Monoid) : + (Monad with type m('a) = writer(W.a, 'a)) => { type m('a) = writer(W.a, 'a); let (>=>) = (f, g, a) => { diff --git a/src/content/3.4/code/reason/snippet17.re b/src/content/3.4/code/reason/snippet17.re index b2ad872f..d53576e3 100644 --- a/src/content/3.4/code/reason/snippet17.re +++ b/src/content/3.4/code/reason/snippet17.re @@ -1,6 +1,7 @@ /* Import Str module using this - #require "str" */ let to_words = s => Writer(Str.split(Str.regexp("\b"), s), "to_words"); -module Writer_Process = (W: Monad with type m('a) = writer(string, 'a)) => { +module Writer_Process = (W: Monad with type m('a) = + writer(string, 'a)) => { let process = W.(up_case >=> to_words); }; diff --git a/src/content/3.4/code/reason/snippet18.re b/src/content/3.4/code/reason/snippet18.re index 984a7e29..4c04e70d 100644 --- a/src/content/3.4/code/reason/snippet18.re +++ b/src/content/3.4/code/reason/snippet18.re @@ -1,6 +1,7 @@ -module Process_Do = (W: Monad_Bind with type m('a) = writer(string, 'a)) => { +module Process_Do = (W: Monad_Bind with type m('a) = + writer(string, 'a)) => { /* Needs Reason parser >= 3.6.0 */ - let ( let* ) = W.(>>=); + let (let*) = W.(>>=); let process = s => { let* up_str = up_case(s); diff --git a/src/content/3.4/code/reason/snippet22.re b/src/content/3.4/code/reason/snippet22.re index f105e00f..f3c87ae5 100644 --- a/src/content/3.4/code/reason/snippet22.re +++ b/src/content/3.4/code/reason/snippet22.re @@ -1,6 +1,7 @@ -module Process_Tell = (W: Monad_Bind with type m('a) = writer(string, 'a)) => { +module Process_Tell = (W: Monad_Bind with type m('a) = + writer(string, 'a)) => { /* Needs Reason parser >= 3.6.0 */ - let ( let* ) = W.(>>=); + let (let*) = W.(>>=); let tell = w => Writer((), w); let process = s => { diff --git a/src/content/3.5/code/reason/snippet03.re b/src/content/3.5/code/reason/snippet03.re index 108ef9a2..4b004ba7 100644 --- a/src/content/3.5/code/reason/snippet03.re +++ b/src/content/3.5/code/reason/snippet03.re @@ -1,5 +1,5 @@ module Pythagorean = { - let ( let* ) = Fn.flip(Gen.flat_map); + let (let*) = Fn.flip(Gen.flat_map); let (let+) = (x, f) => Gen.map(f, x); let guard = b => b ? Gen.return() ? Gen.empty; diff --git a/src/content/3.5/code/reason/snippet05.re b/src/content/3.5/code/reason/snippet05.re index 38b3b02c..e205004a 100644 --- a/src/content/3.5/code/reason/snippet05.re +++ b/src/content/3.5/code/reason/snippet05.re @@ -1,5 +1,5 @@ module Pythagorean = { - let ( let* ) = Fn.flip(Gen.flat_map); + let (let*) = Fn.flip(Gen.flat_map); let (let+) = (x, f) => Gen.map(f, x); let guard = b => b ? Gen.return() : Gen.empty; diff --git a/src/content/3.5/code/reason/snippet12.re b/src/content/3.5/code/reason/snippet12.re index 5d348b28..eb877302 100644 --- a/src/content/3.5/code/reason/snippet12.re +++ b/src/content/3.5/code/reason/snippet12.re @@ -3,5 +3,6 @@ module ReaderMonad = (T: {type t;}) : Monad_Bind => { let return = a => Reader(e => a); - let (>>=) = (ra, k) => Reader(e => run_reader(k(run_reader(ra, e)), e)); + let (>>=) = (ra, k) => + Reader(e => run_reader(k(run_reader(ra, e)), e)); }; diff --git a/src/content/3.5/code/reason/snippet25.re b/src/content/3.5/code/reason/snippet25.re index 4e9ca26c..58dfa0a3 100644 --- a/src/content/3.5/code/reason/snippet25.re +++ b/src/content/3.5/code/reason/snippet25.re @@ -1,5 +1,3 @@ -let (>>=): ( - ('a => 'r) => 'r, +let (>>=): (('a => 'r) => 'r, ('a, 'b => 'r) => 'r, - 'b => 'r -) => 'r; + 'b => 'r) => 'r; diff --git a/src/content/3.5/code/reason/snippet37.re b/src/content/3.5/code/reason/snippet37.re index c4ddf479..c7fa0401 100644 --- a/src/content/3.5/code/reason/snippet37.re +++ b/src/content/3.5/code/reason/snippet37.re @@ -13,7 +13,7 @@ module IOMonad: Monad_Bind with type m('a) = io('a) = { /* main */ module IO_Main = { - let ( let* ) = IOMonad.(>>=); + let (let*) = IOMonad.(>>=); let main = { let* _ = put_str("Hello"); diff --git a/src/content/3.6/code/reason/snippet21.re b/src/content/3.6/code/reason/snippet21.re index 8fc6323e..7a8f17c5 100644 --- a/src/content/3.6/code/reason/snippet21.re +++ b/src/content/3.6/code/reason/snippet21.re @@ -1,10 +1,8 @@ -module AdjunctionState = - ( - S: {type s;}, - F: Functor with type t('a) = prod(S.s, 'a), - R: Representable with type t('a) = reader(S.s, 'a), - ) - : Adjunction => { +module AdjunctionState = ( + S: {type s;}, + F: Functor with type t('a) = prod(S.s, 'a), + R: Representable with type t('a) = reader(S.s, 'a), + ): Adjunction => { type f('a) = prod(S.s, 'a); type r('a) = reader(S.s, 'a); diff --git a/src/content/3.7/code/reason/snippet15.re b/src/content/3.7/code/reason/snippet15.re index 4a699089..88863e17 100644 --- a/src/content/3.7/code/reason/snippet15.re +++ b/src/content/3.7/code/reason/snippet15.re @@ -26,7 +26,8 @@ module type Comonad = { include ComonadDuplicate with type w('a) := w('a); }; -/* Construct a full comonad instance using one of the following modules */ +/* Construct a full comonad instance using one of the +* following modules */ module ComonadImplViaExtend: (C: ComonadBase, D: ComonadDuplicate with type w('a) = C.w('a)) => Comonad with type w('a) = C.w('a) = diff --git a/src/content/3.7/code/reason/snippet20.re b/src/content/3.7/code/reason/snippet20.re index 6671ba81..41347b86 100644 --- a/src/content/3.7/code/reason/snippet20.re +++ b/src/content/3.7/code/reason/snippet20.re @@ -10,7 +10,8 @@ module StreamComonadBase = }; /* Implement duplicate */ -module StreamComonadDuplicate: ComonadDuplicate with type w('a) = stream('a) = { +module StreamComonadDuplicate: ComonadDuplicate with type w('a) = + stream('a) = { type w('a) = stream('a); let rec duplicate = (Cons(x, xs)) => diff --git a/src/content/3.8/code/reason/snippet04.re b/src/content/3.8/code/reason/snippet04.re index 55312ad9..c555bc33 100644 --- a/src/content/3.8/code/reason/snippet04.re +++ b/src/content/3.8/code/reason/snippet04.re @@ -1,8 +1,5 @@ module Ring = { - module RingAlg = - Algebra({ - type f('a) = ring_f('a); - }); + module RingAlg = Algebra({type f('a) = ring_f('a);}); let eval_z: RingAlg.algebra('a) = ( fun @@ -10,7 +7,6 @@ module Ring = { | ROne => 1 | RAdd(m, n) => m + n | RMul(m, n) => m * n - | RNeg(n) => - n: - RingAlg.algebra('a) + | RNeg(n) => - n ); }; diff --git a/src/content/3.8/code/reason/snippet06.re b/src/content/3.8/code/reason/snippet06.re index 60fab083..61adf14a 100644 --- a/src/content/3.8/code/reason/snippet06.re +++ b/src/content/3.8/code/reason/snippet06.re @@ -4,6 +4,5 @@ let rec eval_z: expr => int = ( | ROne => 1 | RAdd(e1, e2) => eval_z(e1) + eval_z(e2) | RMul(e1, e2) => eval_z(e1) * eval_z(e2) - | RNeg(e) => - eval_z(e): - expr => int + | RNeg(e) => - eval_z(e) ); diff --git a/src/content/3.8/code/reason/snippet26.re b/src/content/3.8/code/reason/snippet26.re index cfb65ee8..9b013891 100644 --- a/src/content/3.8/code/reason/snippet26.re +++ b/src/content/3.8/code/reason/snippet26.re @@ -1,9 +1,8 @@ type stream_f('e, 'a) = | StreamF(('e, 'a)); -module Stream_Functor = - (E: {type e;}) - : (Functor with type t('a) = stream_f(E.e, 'a)) => { +module Stream_Functor = (E: {type e;}) : + (Functor with type t('a) = stream_f(E.e, 'a)) => { type t('a) = stream_f(E.e, 'a); let fmap = f => diff --git a/src/content/3.8/code/reason/snippet28.re b/src/content/3.8/code/reason/snippet28.re index f5f82ae8..6f6d7697 100644 --- a/src/content/3.8/code/reason/snippet28.re +++ b/src/content/3.8/code/reason/snippet28.re @@ -2,11 +2,8 @@ potentially infinite iterators. You can install it with `opam install gen`. To use it in the toplevel, you need to `#require "gen"` */ -let era: Gen.t(int) => stream_f(int, Gen.t(int)) = ( - ilist => { +let era: Gen.t(int) => stream_f(int, Gen.t(int)) = (ilist => { let notdiv = (p, n) => n mod p !== 0; let p = Gen.get_exn(ilist); StreamF(p, Gen.filter(notdiv(p), ilist)); - }: - Gen.t(int) => stream_f(int, Gen.t(int)) -); +}); \ No newline at end of file diff --git a/src/content/3.8/code/reason/snippet29.re b/src/content/3.8/code/reason/snippet29.re index bac17fc5..0cf51c09 100644 --- a/src/content/3.8/code/reason/snippet29.re +++ b/src/content/3.8/code/reason/snippet29.re @@ -1,11 +1,8 @@ -module Stream_Int = - Stream_Functor({ - type e = int; - }); +module Stream_Int = Stream_Functor({type e = int;}); module Ana_Stream = Ana(Stream_Int); -/* The fixpoint translated to OCaml is eager in its evaluation. +/* The fixpoint translated to ReasonML is eager in its evaluation. Hence, executing the following function will cause overflow. So, wrapping it inside a lazy */ let primes = lazy(Ana_Stream.ana(era, Gen.init(i => i + 2))); diff --git a/src/content/3.8/code/reason/snippet31.re b/src/content/3.8/code/reason/snippet31.re index 1ec9d084..7eae382d 100644 --- a/src/content/3.8/code/reason/snippet31.re +++ b/src/content/3.8/code/reason/snippet31.re @@ -1,2 +1,3 @@ -/* Gen.t is used to represent infinite data structures like haskell's lazy list */ +/* Gen.t is used to represent infinite data structures + like haskell's lazy list */ let unfold: ('b => option(('a, 'b)), 'b) => Gen.t('a); diff --git a/src/content/3.9/code/reason/snippet03.re b/src/content/3.9/code/reason/snippet03.re index 03062ed6..243cd64f 100644 --- a/src/content/3.9/code/reason/snippet03.re +++ b/src/content/3.9/code/reason/snippet03.re @@ -1,3 +1,2 @@ /* List module in the OCaml standard library accepts list before z */ - List.fold_right(f, [x], z) == f(x, z); diff --git a/src/content/3.9/code/reason/snippet09.re b/src/content/3.9/code/reason/snippet09.re index 1262235a..e7f1e1c4 100644 --- a/src/content/3.9/code/reason/snippet09.re +++ b/src/content/3.9/code/reason/snippet09.re @@ -1,6 +1,5 @@ -module Store_Functor = - (S: {type s;}) - : (Functor with type t('a) = store(S.s, 'a)) => { +module Store_Functor = (S: {type s;}) : + (Functor with type t('a) = store(S.s, 'a)) => { type w('a) = store(S.s, 'a); type t('a) = w('a);