From e4e67f0427d93b3686366ffe9f14a4751690101e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 2 May 2018 00:09:35 -0400 Subject: - Moved the "wrap" function into Monad, and removed Applicative from Monad's family tree. - Moved the Free monad to its own module. --- stdlib/test/test/lux/control/continuation.lux | 3 ++- stdlib/test/test/lux/control/reader.lux | 34 ++++++++++++++------------- stdlib/test/test/lux/control/state.lux | 18 +++++++------- stdlib/test/test/lux/control/writer.lux | 3 ++- stdlib/test/test/lux/data/coll/list.lux | 4 ++-- stdlib/test/test/lux/data/coll/sequence.lux | 1 + stdlib/test/test/lux/data/error.lux | 3 ++- stdlib/test/test/lux/data/identity.lux | 3 ++- stdlib/test/test/lux/data/lazy.lux | 19 ++++++--------- stdlib/test/test/lux/data/maybe.lux | 11 +++++---- stdlib/test/test/lux/io.lux | 5 ++-- stdlib/test/test/lux/lang/syntax.lux | 3 ++- stdlib/test/test/lux/time/date.lux | 3 ++- stdlib/test/tests.lux | 18 +++++++------- 14 files changed, 68 insertions(+), 60 deletions(-) (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/control/continuation.lux b/stdlib/test/test/lux/control/continuation.lux index db274189e..ad50a5515 100644 --- a/stdlib/test/test/lux/control/continuation.lux +++ b/stdlib/test/test/lux/control/continuation.lux @@ -15,7 +15,8 @@ (<| (times +100) (do @ [sample r.nat - #let [(^open "&/") &.Monad] + #let [(^open "&/") &.Applicative + (^open "&/") &.Monad] elems (r.list +3 r.nat)] ($_ seq (test "Can run continuations to compute their values." diff --git a/stdlib/test/test/lux/control/reader.lux b/stdlib/test/test/lux/control/reader.lux index 38b4f2893..4eab1d6f3 100644 --- a/stdlib/test/test/lux/control/reader.lux +++ b/stdlib/test/test/lux/control/reader.lux @@ -10,26 +10,28 @@ lux/test) (context: "Readers" - ($_ seq - (test "" (i/= 123 (&.run 123 &.ask))) - (test "" (i/= 246 (&.run 123 (&.local (i/* 2) &.ask)))) - (test "" (i/= 134 (&.run 123 (:: &.Functor map i/inc (i/+ 10))))) - (test "" (i/= 10 (&.run 123 (:: &.Applicative wrap 10)))) - (test "" (i/= 30 (&.run 123 (let [(^open "&/") &.Applicative] - (&/apply (&/wrap (i/+ 10)) (&/wrap 20)))))) - (test "" (i/= 30 (&.run 123 (do &.Monad - [f (wrap i/+) - x (wrap 10) - y (wrap 20)] - (wrap (f x y)))))))) + (let [(^open "&/") &.Applicative + (^open "&/") &.Monad] + ($_ seq + (test "" (i/= 123 (&.run 123 &.ask))) + (test "" (i/= 246 (&.run 123 (&.local (i/* 2) &.ask)))) + (test "" (i/= 134 (&.run 123 (&/map i/inc (i/+ 10))))) + (test "" (i/= 10 (&.run 123 (&/wrap 10)))) + (test "" (i/= 30 (&.run 123 (&/apply (&/wrap (i/+ 10)) (&/wrap 20))))) + (test "" (i/= 30 (&.run 123 (do &.Monad + [f (wrap i/+) + x (wrap 10) + y (wrap 20)] + (wrap (f x y))))))))) (context: "Monad transformer" (let [(^open "io/") io.Monad] (test "Can add reader functionality to any monad." - (|> (do (&.ReaderT io.Monad) - [a (&.lift (io/wrap 123)) - b (wrap 456)] - (wrap (i/+ a b))) + (|> (: (&.Reader Text (io.IO Int)) + (do (&.ReaderT io.Monad) + [a (&.lift (io/wrap 123)) + b (wrap 456)] + (wrap (i/+ a b)))) (&.run "") io.run (case> 579 true diff --git a/stdlib/test/test/lux/control/state.lux b/stdlib/test/test/lux/control/state.lux index 4457952a1..396b390e7 100644 --- a/stdlib/test/test/lux/control/state.lux +++ b/stdlib/test/test/lux/control/state.lux @@ -50,18 +50,20 @@ (<| (times +100) (do @ [state r.nat - value r.nat] + value r.nat + #let [(^open "&/") &.Functor + (^open "&/") &.Applicative + (^open "&/") &.Monad]] ($_ seq (test "Can use functor." (with-conditions [state (n/inc state)] - (:: &.Functor map n/inc &.get))) + (&/map n/inc &.get))) (test "Can use applicative." - (let [(^open "&/") &.Applicative] - (and (with-conditions [state value] - (&/wrap value)) - (with-conditions [state (n/+ value value)] - (&/apply (&/wrap (n/+ value)) - (&/wrap value)))))) + (and (with-conditions [state value] + (&/wrap value)) + (with-conditions [state (n/+ value value)] + (&/apply (&/wrap (n/+ value)) + (&/wrap value))))) (test "Can use monad." (with-conditions [state (n/+ value value)] (: (&.State Nat Nat) diff --git a/stdlib/test/test/lux/control/writer.lux b/stdlib/test/test/lux/control/writer.lux index 42a5f9543..6139db20e 100644 --- a/stdlib/test/test/lux/control/writer.lux +++ b/stdlib/test/test/lux/control/writer.lux @@ -10,7 +10,8 @@ lux/test) (context: "Writer." - (let [(^open "&/") (&.Monad text.Monoid)] + (let [(^open "&/") (&.Monad text.Monoid) + (^open "&/") (&.Applicative text.Monoid)] ($_ seq (test "Functor respects Writer." (i/= 11 (product.right (&/map i/inc ["" 10])))) diff --git a/stdlib/test/test/lux/data/coll/list.lux b/stdlib/test/test/lux/data/coll/list.lux index ebc650df6..f9e6e31b9 100644 --- a/stdlib/test/test/lux/data/coll/list.lux +++ b/stdlib/test/test/lux/data/coll/list.lux @@ -4,7 +4,6 @@ (control [monad #+ do Monad] pipe) (data (coll ["&" list]) - [text "Text/" Monoid] [number] [bool] [product] @@ -175,7 +174,8 @@ (= other-sample right)))))) (test "Applicative allows you to create singleton lists, and apply lists of functions to lists of values." - (let [(^open) &.Applicative] + (let [(^open) &.Monad + (^open) &.Applicative] (and (= (list separator) (wrap separator)) (= (map n/inc sample) (apply (wrap n/inc) sample))))) diff --git a/stdlib/test/test/lux/data/coll/sequence.lux b/stdlib/test/test/lux/data/coll/sequence.lux index afeca6154..e64377f21 100644 --- a/stdlib/test/test/lux/data/coll/sequence.lux +++ b/stdlib/test/test/lux/data/coll/sequence.lux @@ -18,6 +18,7 @@ other-sample (r.sequence size r.nat) non-member (|> r.nat (r.filter (|>> (&.member? number.Eq sample) not))) #let [(^open "&/") (&.Eq number.Eq) + (^open "&/") &.Applicative (^open "&/") &.Monad (^open "&/") &.Fold (^open "&/") &.Monoid]] diff --git a/stdlib/test/test/lux/data/error.lux b/stdlib/test/test/lux/data/error.lux index f6c7d7a70..84556fde7 100644 --- a/stdlib/test/test/lux/data/error.lux +++ b/stdlib/test/test/lux/data/error.lux @@ -8,7 +8,8 @@ lux/test) (context: "Errors" - (let [(^open "&/") &.Monad] + (let [(^open "&/") &.Applicative + (^open "&/") &.Monad] ($_ seq (test "Functor correctly handles both cases." (and (|> (: (&.Error Int) (#&.Success 10)) diff --git a/stdlib/test/test/lux/data/identity.lux b/stdlib/test/test/lux/data/identity.lux index 7ab4a6399..9e36efda5 100644 --- a/stdlib/test/test/lux/data/identity.lux +++ b/stdlib/test/test/lux/data/identity.lux @@ -8,7 +8,8 @@ lux/test) (context: "Identity" - (let [(^open "&/") &.Monad + (let [(^open "&/") &.Applicative + (^open "&/") &.Monad (^open "&/") &.CoMonad] ($_ seq (test "Functor does not affect values." diff --git a/stdlib/test/test/lux/data/lazy.lux b/stdlib/test/test/lux/data/lazy.lux index 1b8a76730..b683abb0f 100644 --- a/stdlib/test/test/lux/data/lazy.lux +++ b/stdlib/test/test/lux/data/lazy.lux @@ -35,18 +35,6 @@ &.thaw (n/= (n/inc sample)))) - (test "Applicative wrap." - (|> sample - (:: &.Applicative wrap) - &.thaw - (n/= sample))) - - (test "Applicative apply." - (let [(^open "&/") &.Applicative] - (|> (&/apply (&/wrap n/inc) (&/wrap sample)) - &.thaw - (n/= (n/inc sample))))) - (test "Monad." (|> (do &.Monad [f (wrap n/inc) @@ -54,4 +42,11 @@ (wrap (f a))) &.thaw (n/= (n/inc sample)))) + + (test "Applicative apply." + (let [(^open "&/") &.Monad + (^open "&/") &.Applicative] + (|> (&/apply (&/wrap n/inc) (&/wrap sample)) + &.thaw + (n/= (n/inc sample))))) )))) diff --git a/stdlib/test/test/lux/data/maybe.lux b/stdlib/test/test/lux/data/maybe.lux index 4a2c98ab7..ca11da17f 100644 --- a/stdlib/test/test/lux/data/maybe.lux +++ b/stdlib/test/test/lux/data/maybe.lux @@ -4,12 +4,13 @@ (control ["M" monad #+ do Monad] pipe) (data ["&" maybe] - [text "Text/" Monoid] + [text "text/" Monoid] [number])) lux/test) (context: "Maybe" (let [(^open "&/") &.Monoid + (^open "&/") &.Applicative (^open "&/") &.Monad (^open "Maybe/") (&.Eq text.Eq)] ($_ seq @@ -27,18 +28,18 @@ (Maybe/= #.None (: (Maybe Text) (&/compose #.None #.None))))) (test "Functor respects Maybe." - (and (Maybe/= #.None (&/map (Text/compose "yolo") #.None)) - (Maybe/= (#.Some "yololol") (&/map (Text/compose "yolo") (#.Some "lol"))))) + (and (Maybe/= #.None (&/map (text/compose "yolo") #.None)) + (Maybe/= (#.Some "yololol") (&/map (text/compose "yolo") (#.Some "lol"))))) (test "Applicative respects Maybe." (and (Maybe/= (#.Some "yolo") (&/wrap "yolo")) (Maybe/= (#.Some "yololol") - (&/apply (&/wrap (Text/compose "yolo")) (&/wrap "lol"))))) + (&/apply (&/wrap (text/compose "yolo")) (&/wrap "lol"))))) (test "Monad respects Maybe." (Maybe/= (#.Some "yololol") (do &.Monad - [f (wrap Text/compose) + [f (wrap text/compose) a (wrap "yolo") b (wrap "lol")] (wrap (f a b))))) diff --git a/stdlib/test/test/lux/io.lux b/stdlib/test/test/lux/io.lux index 20b3be116..5836e5844 100644 --- a/stdlib/test/test/lux/io.lux +++ b/stdlib/test/test/lux/io.lux @@ -11,8 +11,9 @@ ($_ seq (test "" (Text/= "YOLO" (&.run (&.io "YOLO")))) (test "" (i/= 11 (&.run (:: &.Functor map i/inc (&.io 10))))) - (test "" (i/= 10 (&.run (:: &.Applicative wrap 10)))) - (test "" (i/= 30 (&.run (let [(^open "&/") &.Applicative] + (test "" (i/= 10 (&.run (:: &.Monad wrap 10)))) + (test "" (i/= 30 (&.run (let [(^open "&/") &.Applicative + (^open "&/") &.Monad] (&/apply (&/wrap (i/+ 10)) (&/wrap 20)))))) (test "" (i/= 30 (&.run (do &.Monad [f (wrap i/+) diff --git a/stdlib/test/test/lux/lang/syntax.lux b/stdlib/test/test/lux/lang/syntax.lux index 4e6bed9bc..9d1f18ae5 100644 --- a/stdlib/test/test/lux/lang/syntax.lux +++ b/stdlib/test/test/lux/lang/syntax.lux @@ -166,7 +166,8 @@ (wrap (format "#( " comment " )#"))))))) (context: "Multi-line text & comments." - (<| (times +100) + (<| (seed +12137892244981970631) + ## (times +100) (do @ [#let [char-gen (|> r.nat (r.filter (function (_ value) (not (or (text.space? value) diff --git a/stdlib/test/test/lux/time/date.lux b/stdlib/test/test/lux/time/date.lux index 8e8c77860..8dba5517a 100644 --- a/stdlib/test/test/lux/time/date.lux +++ b/stdlib/test/test/lux/time/date.lux @@ -126,7 +126,8 @@ (@/<= reference sample))))))) (context: "(Date) Codec" - (<| (times +100) + (<| (seed +6623983470548808292) + ## (times +100) (do @ [sample date #let [(^open "@/") @.Eq diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 71317af18..d4a0c0a32 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -27,16 +27,16 @@ ["_." region]) (data ["_." bit] ["_." bool] + ["_." color] ["_." error] ["_." ident] ["_." identity] + ["_." lazy] ["_." maybe] - ["_." number] ["_." product] ["_." sum] ["_." text] - ["_." lazy] - ["_." color] + ["_." number] (number ["_." ratio] ["_." complex]) (format ["_." json] @@ -69,11 +69,11 @@ (poly ["poly_." eq] ["poly_." functor])) (type ["_." implicit] + ["_." resource] (object ["_." interface] - ["_." protocol]) - ["_." resource]) - (lang ["lang/_." syntax] + ["_." protocol])) + (lang ["_lang/." syntax] ["_." type] (type ["_." check])) (world ["_." blob] @@ -82,7 +82,8 @@ ["_." udp])))) (lux (control [contract] [concatenative] - [predicate]) + [predicate] + [monad/free]) (data [env] [trace] [store] @@ -97,8 +98,7 @@ [refinement] [quotient]) [world/env] - [world/console]) - ) + [world/console])) (program: args (test.run)) -- cgit v1.2.3