on master help sign in
Merge pull request #1174 from bmsherman/master
e7e5638Edwin Brady
libs/effects/Effects.idr+2−2
@@ -337,8 +337,8 @@ mapVE f [] = pure []
337mapVE f (x :: xs) = [| f x :: mapVE f xs |]
337mapVE f (x :: xs) = [| f x :: mapVE f xs |]
338
338
339
339
340−when : Applicative m => Bool -> ({xs} Eff m ()) -> {xs} Eff m ()
340+when : Applicative m => Bool -> Lazy ({xs} Eff m ()) -> {xs} Eff m ()
341−when True e = e
341+when True e = Force e
342when False e = pure ()
342when False e = pure ()
343
343
344-- --------------------------------------------------------------------- [ EOF ]
344-- --------------------------------------------------------------------- [ EOF ]
libs/oldeffects/Effects.idr+1−1
@@ -303,6 +303,6 @@ mapE : Applicative m => (a -> Eff m xs b) -> List a -> Eff m xs (List b)
303mapE f [] = pure []
303mapE f [] = pure []
304mapE f (x :: xs) = [| f x :: mapE f xs |]
304mapE f (x :: xs) = [| f x :: mapE f xs |]
305
305
306−when : Applicative m => Bool -> Eff m xs () -> Eff m xs ()
306+when : Applicative m => Bool -> Lazy (Eff m xs ()) -> Eff m xs ()
307when True e = e
307when True e = e
308when False e = pure ()
308when False e = pure ()
libs/prelude/Prelude/Applicative.idr+5−2
@@ -38,8 +38,11 @@ class Applicative f => Alternative (f : Type -> Type) where
38 empty : f a
38 empty : f a
39 (<|>) : f a -> f a -> f a
39 (<|>) : f a -> f a -> f a
40
40
41+||| `guard a` is `pure ()` if `a` is `True` and `empty` if `a` is `False`
41guard : Alternative f => Bool -> f ()
42guard : Alternative f => Bool -> f ()
42guard a = if a then pure () else empty
43guard a = if a then pure () else empty
43
44
45+||| Conditionally execute an applicative expression
44−when : Applicative f => Bool -> f () -> f ()
46+when : Applicative f => Bool -> Lazy (f ()) -> f ()
45−when a f = if a then f else pure ()
47+when True f = Force f
48+when False f = pure ()
libs/prelude/Prelude/Bool.idr+4−4
@@ -27,13 +27,13 @@ syntax if [test] then [t] else [e] = boolElim test (Delay t) (Delay e)
27-- Boolean Operator Precedence
27-- Boolean Operator Precedence
28infixl 4 &&, ||
28infixl 4 &&, ||
29
29
30−||| Boolean OR
30+||| Boolean OR only evaluates the second argument if the first is `False`.
31−(||) : Bool -> Bool -> Bool
31+(||) : Bool -> Lazy Bool -> Bool
32(||) False x = x
32(||) False x = x
33(||) True _ = True
33(||) True _ = True
34
34
35−||| Boolean AND
35+||| Boolean AND only evaluates the second argument if the first is `True`.
36−(&&) : Bool -> Bool -> Bool
36+(&&) : Bool -> Lazy Bool -> Bool
37(&&) True x = x
37(&&) True x = x
38(&&) False _ = False
38(&&) False _ = False
39
39
libs/prelude/Prelude/Either.idr+4−4
@@ -39,9 +39,9 @@ choose False = Right oh
39||| @ f the action to take on Left
39||| @ f the action to take on Left
40||| @ g the action to take on Right
40||| @ g the action to take on Right
41||| @ e the sum to analyze
41||| @ e the sum to analyze
42−either : (f : a -> c) -> (g : b -> c) -> (e : Either a b) -> c
42+either : (f : Lazy (a -> c)) -> (g : Lazy (b -> c)) -> (e : Either a b) -> c
43−either l r (Left x) = l x
43+either l r (Left x) = (Force l) x
44−either l r (Right x) = r x
44+either l r (Right x) = (Force r) x
45
45
46||| Keep the payloads of all Left constructors in a list of Eithers
46||| Keep the payloads of all Left constructors in a list of Eithers
47lefts : List (Either a b) -> List a
47lefts : List (Either a b) -> List a
@@ -74,7 +74,7 @@ fromEither (Right r) = r
74
74
75||| Convert a Maybe to an Either by using a default value in case of Nothing
75||| Convert a Maybe to an Either by using a default value in case of Nothing
76||| @ e the default value
76||| @ e the default value
77−maybeToEither : (def : e) -> Maybe a -> Either e a
77+maybeToEither : (def : Lazy e) -> Maybe a -> Either e a
78maybeToEither def (Just j) = Right j
78maybeToEither def (Just j) = Right j
79maybeToEither def Nothing = Left def
79maybeToEither def Nothing = Left def
80
80
libs/prelude/Prelude/Foldable.idr+25−8
@@ -14,27 +14,44 @@ class Foldable (t : Type -> Type) where
14foldl : Foldable t => (acc -> elt -> acc) -> acc -> t elt -> acc
14foldl : Foldable t => (acc -> elt -> acc) -> acc -> t elt -> acc
15foldl f z t = foldr (flip (.) . flip f) id t z
15foldl f z t = foldr (flip (.) . flip f) id t z
16
16
17+||| Combine each element of a structure into a monoid
17concat : (Foldable t, Monoid a) => t a -> a
18concat : (Foldable t, Monoid a) => t a -> a
18concat = foldr (<+>) neutral
19concat = foldr (<+>) neutral
19
20
21+||| Combine into a monoid the collective results of applying a function
22+||| to each element of a structure
20concatMap : (Foldable t, Monoid m) => (a -> m) -> t a -> m
23concatMap : (Foldable t, Monoid m) => (a -> m) -> t a -> m
21concatMap f = foldr ((<+>) . f) neutral
24concatMap f = foldr ((<+>) . f) neutral
22
25
26+||| The conjunction of all elements of a structure containing
27+||| lazy boolean values. `and` short-circuits from left to right,
28+||| evaluating until either an element is `False` or no elements remain.
23−and : Foldable t => t Bool -> Bool
29+and : Foldable t => t (Lazy Bool) -> Bool
24−and = foldr (&&) True
30+and = foldl (&&) True
25−
31+
32+||| The disjunction of all elements of a structure containing
33+||| lazy boolean values. `or` short-circuits from left to right, evaluating
34+||| either until an element is `True` or no elements remain.
26−or : Foldable t => t Bool -> Bool
35+or : Foldable t => t (Lazy Bool) -> Bool
27−or = foldr (||) False
36+or = foldl (||) False
28−
37+
38+||| The disjunction of the collective results of applying a
39+||| predicate to all elements of a structure. `any` short-circuits
40+||| from left to right.
29any : Foldable t => (a -> Bool) -> t a -> Bool
41any : Foldable t => (a -> Bool) -> t a -> Bool
30−any p = foldr ((||) . p) False
42+any p = foldl (\x => \y => x || p y) False
31
43
44+||| The disjunction of the collective results of applying a
45+||| predicate to all elements of a structure. `all` short-circuits
46+||| from left to right.
32all : Foldable t => (a -> Bool) -> t a -> Bool
47all : Foldable t => (a -> Bool) -> t a -> Bool
33−all p = foldr ((&&) . p) True
48+all p = foldl (\x => \y => x && p y) True
34
49
50+||| Add together all the elements of a structure
35sum : (Foldable t, Num a) => t a -> a
51sum : (Foldable t, Num a) => t a -> a
36sum = foldr (+) 0
52sum = foldr (+) 0
37
53
54+||| Multiply together all elements of a structure
38product : (Foldable t, Num a) => t a -> a
55product : (Foldable t, Num a) => t a -> a
39product = foldr (*) 1
56product = foldr (*) 1
40
57
libs/prelude/Prelude/List.idr+2−2
@@ -182,9 +182,9 @@ dropWhile p (x::xs) = if p x then dropWhile p xs else x::xs
182||| @ nil what to return at the end of the list
182||| @ nil what to return at the end of the list
183||| @ cons what to do at each step of recursion
183||| @ cons what to do at each step of recursion
184||| @ xs the list to recurse over
184||| @ xs the list to recurse over
185−list : (nil : a) -> (cons : a -> List a -> a) -> (xs : List a) -> a
185+list : (nil : Lazy b) -> (cons : Lazy (a -> List a -> b)) -> (xs : List a) -> b
186list nil cons [] = nil
186list nil cons [] = nil
187−list nil cons (x::xs) = cons x xs
187+list nil cons (x::xs) = (Force cons) x xs
188
188
189--------------------------------------------------------------------------------
189--------------------------------------------------------------------------------
190-- Building (bigger) lists
190-- Building (bigger) lists
libs/prelude/Prelude/Maybe.idr+10−3
@@ -28,25 +28,32 @@ isJust (Just j) = True
28-- Misc
28-- Misc
29--------------------------------------------------------------------------------
29--------------------------------------------------------------------------------
30
30
31−maybe : Lazy b -> (a -> b) -> Maybe a -> b
31+maybe : Lazy b -> Lazy (a -> b) -> Maybe a -> b
32maybe n j Nothing = n
32maybe n j Nothing = n
33−maybe n j (Just x) = j x
33+maybe n j (Just x) = (Force j) x
34
34
35+||| Convert a `Maybe a` value to an `a` value by providing a default `a` value
36+||| in the case that the `Maybe` value is `Nothing`.
35fromMaybe : (Lazy a) -> Maybe a -> a
37fromMaybe : (Lazy a) -> Maybe a -> a
36fromMaybe def Nothing = def
38fromMaybe def Nothing = def
37fromMaybe def (Just j) = j
39fromMaybe def (Just j) = j
38
40
41+||| Returns `Just` the given value if the conditional is `True`
42+||| and `Nothing` if the conditional is `False`.
39−toMaybe : Bool -> a -> Maybe a
43+toMaybe : Bool -> Lazy a -> Maybe a
40toMaybe True j = Just j
44toMaybe True j = Just j
41toMaybe False j = Nothing
45toMaybe False j = Nothing
42
46
43justInjective : {x : t} -> {y : t} -> (Just x = Just y) -> x = y
47justInjective : {x : t} -> {y : t} -> (Just x = Just y) -> x = y
44justInjective refl = refl
48justInjective refl = refl
45
49
50+||| Convert a `Maybe a` value to an `a` value, using `neutral` in the case
51+||| that the `Maybe` value is `Nothing`.
46lowerMaybe : Monoid a => Maybe a -> a
52lowerMaybe : Monoid a => Maybe a -> a
47lowerMaybe Nothing = neutral
53lowerMaybe Nothing = neutral
48lowerMaybe (Just x) = x
54lowerMaybe (Just x) = x
49
55
56+||| Returns `Nothing` when applied to `neutral`, and `Just` the value otherwise.
50raiseToMaybe : (Monoid a, Eq a) => a -> Maybe a
57raiseToMaybe : (Monoid a, Eq a) => a -> Maybe a
51raiseToMaybe x = if x == neutral then Nothing else Just x
58raiseToMaybe x = if x == neutral then Nothing else Just x
52
59
libs/prelude/Prelude/Stream.idr+3−1
@@ -31,8 +31,10 @@ take : (n : Nat) -> (xs : Stream a) -> Vect n a
31take Z _ = []
31take Z _ = []
32take (S n) (x :: xs) = x :: (take n xs)
32take (S n) (x :: xs) = x :: (take n xs)
33
33
34+||| Drop the first n elements from the stream
35+||| @ n how many elements to drop
34%assert_total
36%assert_total
35−drop : Nat -> Stream a -> Stream a
37+drop : (n : Nat) -> Stream a -> Stream a
36drop Z xs = xs
38drop Z xs = xs
37drop (S k) (x::xs) = drop k xs
39drop (S k) (x::xs) = drop k xs
38
40