diff options
author | Eduardo Julian | 2018-05-02 00:09:35 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-05-02 00:09:35 -0400 |
commit | e4e67f0427d93b3686366ffe9f14a4751690101e (patch) | |
tree | 22857a6ea96f97925bacc5ea2ddf71ab55207569 /stdlib/test | |
parent | 9906f649d26adfed5126065082fb4a7d5e4696bb (diff) |
- Moved the "wrap" function into Monad, and removed Applicative from Monad's family tree.
- Moved the Free monad to its own module.
Diffstat (limited to '')
-rw-r--r-- | stdlib/test/test/lux/control/continuation.lux | 3 | ||||
-rw-r--r-- | stdlib/test/test/lux/control/reader.lux | 34 | ||||
-rw-r--r-- | stdlib/test/test/lux/control/state.lux | 18 | ||||
-rw-r--r-- | stdlib/test/test/lux/control/writer.lux | 3 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/coll/list.lux | 4 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/coll/sequence.lux | 1 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/error.lux | 3 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/identity.lux | 3 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/lazy.lux | 19 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/maybe.lux | 11 | ||||
-rw-r--r-- | stdlib/test/test/lux/io.lux | 5 | ||||
-rw-r--r-- | stdlib/test/test/lux/lang/syntax.lux | 3 | ||||
-rw-r--r-- | stdlib/test/test/lux/time/date.lux | 3 | ||||
-rw-r--r-- | stdlib/test/tests.lux | 18 |
14 files changed, 68 insertions, 60 deletions
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<Cont>] + #let [(^open "&/") &.Applicative<Cont> + (^open "&/") &.Monad<Cont>] 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<Reader> map i/inc (i/+ 10))))) - (test "" (i/= 10 (&.run 123 (:: &.Applicative<Reader> wrap 10)))) - (test "" (i/= 30 (&.run 123 (let [(^open "&/") &.Applicative<Reader>] - (&/apply (&/wrap (i/+ 10)) (&/wrap 20)))))) - (test "" (i/= 30 (&.run 123 (do &.Monad<Reader> - [f (wrap i/+) - x (wrap 10) - y (wrap 20)] - (wrap (f x y)))))))) + (let [(^open "&/") &.Applicative<Reader> + (^open "&/") &.Monad<Reader>] + ($_ 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<Reader> + [f (wrap i/+) + x (wrap 10) + y (wrap 20)] + (wrap (f x y))))))))) (context: "Monad transformer" (let [(^open "io/") io.Monad<IO>] (test "Can add reader functionality to any monad." - (|> (do (&.ReaderT io.Monad<IO>) - [a (&.lift (io/wrap 123)) - b (wrap 456)] - (wrap (i/+ a b))) + (|> (: (&.Reader Text (io.IO Int)) + (do (&.ReaderT io.Monad<IO>) + [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<State> + (^open "&/") &.Applicative<State> + (^open "&/") &.Monad<State>]] ($_ seq (test "Can use functor." (with-conditions [state (n/inc state)] - (:: &.Functor<State> map n/inc &.get))) + (&/map n/inc &.get))) (test "Can use applicative." - (let [(^open "&/") &.Applicative<State>] - (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<Writer> text.Monoid<Text>)] + (let [(^open "&/") (&.Monad<Writer> text.Monoid<Text>) + (^open "&/") (&.Applicative<Writer> text.Monoid<Text>)] ($_ 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<Text>] [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<List>] + (let [(^open) &.Monad<List> + (^open) &.Applicative<List>] (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<Nat> sample) not))) #let [(^open "&/") (&.Eq<Sequence> number.Eq<Nat>) + (^open "&/") &.Applicative<Sequence> (^open "&/") &.Monad<Sequence> (^open "&/") &.Fold<Sequence> (^open "&/") &.Monoid<Sequence>]] 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<Error>] + (let [(^open "&/") &.Applicative<Error> + (^open "&/") &.Monad<Error>] ($_ 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<Identity> + (let [(^open "&/") &.Applicative<Identity> + (^open "&/") &.Monad<Identity> (^open "&/") &.CoMonad<Identity>] ($_ 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<Lazy> wrap) - &.thaw - (n/= sample))) - - (test "Applicative apply." - (let [(^open "&/") &.Applicative<Lazy>] - (|> (&/apply (&/wrap n/inc) (&/wrap sample)) - &.thaw - (n/= (n/inc sample))))) - (test "Monad." (|> (do &.Monad<Lazy> [f (wrap n/inc) @@ -54,4 +42,11 @@ (wrap (f a))) &.thaw (n/= (n/inc sample)))) + + (test "Applicative apply." + (let [(^open "&/") &.Monad<Lazy> + (^open "&/") &.Applicative<Lazy>] + (|> (&/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 "text/" Monoid<Text>] [number])) lux/test) (context: "Maybe" (let [(^open "&/") &.Monoid<Maybe> + (^open "&/") &.Applicative<Maybe> (^open "&/") &.Monad<Maybe> (^open "Maybe/") (&.Eq<Maybe> text.Eq<Text>)] ($_ 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<Maybe> - [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<IO> map i/inc (&.io 10))))) - (test "" (i/= 10 (&.run (:: &.Applicative<IO> wrap 10)))) - (test "" (i/= 30 (&.run (let [(^open "&/") &.Applicative<IO>] + (test "" (i/= 10 (&.run (:: &.Monad<IO> wrap 10)))) + (test "" (i/= 30 (&.run (let [(^open "&/") &.Applicative<IO> + (^open "&/") &.Monad<IO>] (&/apply (&/wrap (i/+ 10)) (&/wrap 20)))))) (test "" (i/= 30 (&.run (do &.Monad<IO> [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<Date> 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)) |