Verified Commit 6e9b5bfe authored by Camil Staps's avatar Camil Staps 🙂

Add strictness annotations in some high-frequency modules

parent deca53aa
Pipeline #16226 passed with stage
in 1 minute and 14 seconds
......@@ -33,16 +33,16 @@ mapM :: (.a -> b c) ![.a] -> b [c] | Monad b
mapM_ :: (.a -> b c) ![.a] -> b () | Monad b
forM :: u:([v:a] -> w:((v:a -> b c) -> b [c])) | Monad b, [w <= u,w <= v]
forM_ :: u:([v:a] -> w:((v:a -> b c) -> b ())) | Monad b, [w <= u,w <= v]
forever :: (a b) -> a c | Monad a
join :: (a (a b)) -> a b | Monad a
forever :: !(a b) -> a c | Monad a
join :: !(a (a b)) -> a b | Monad a
zipWithM :: (.a -> .(.b -> c d)) ![.a] [.b] -> c [d] | Monad c
foldM :: (a -> .(b -> c a)) a ![b] -> c a | Monad c
replicateM :: !.Int (a b) -> a [b] | Monad a
(>=>) infixr 1 :: u:(.a -> b c) (c -> b d) -> v:(.a -> b d) | Monad b, [v <= u]
(<=<) infixr 1 :: u:((a -> b c) -> v:(w:(.d -> b a) -> x:(.d -> b c))) | Monad b, [v <= u,x <= w]
liftM :: (a -> b) (c a) -> c b | Monad c
liftM2 :: (a -> .(b -> c)) (d a) (d b) -> d c | Monad d
liftM3 :: (a -> .(b -> .(c -> d))) (e a) (e b) (e c) -> e d | Monad e
liftM4 :: (a -> .(b -> .(c -> .(d -> e)))) (f a) (f b) (f c) (f d) -> f e | Monad f
liftM5 :: (a -> .(b -> .(c -> .(d -> .(e -> f))))) (g a) (g b) (g c) (g d) (g e) -> g f | Monad g
liftM :: (a -> b) !(c a) -> c b | Monad c
liftM2 :: (a -> .(b -> c)) !(d a) (d b) -> d c | Monad d
liftM3 :: (a -> .(b -> .(c -> d))) !(e a) (e b) (e c) -> e d | Monad e
liftM4 :: (a -> .(b -> .(c -> .(d -> e)))) !(f a) (f b) (f c) (f d) -> f e | Monad f
liftM5 :: (a -> .(b -> .(c -> .(d -> .(e -> f))))) !(g a) (g b) (g c) (g d) (g e) -> g f | Monad g
ap :: u:((a (b -> c)) -> v:((a b) -> a c)) | Monad a, [v <= u]
......@@ -27,10 +27,10 @@ forM = flip mapM
forM_ :: u:([v:a] -> w:((v:a -> b c) -> b ())) | Monad b, [w <= u,w <= v]
forM_ = flip mapM_
forever :: (a b) -> a c | Monad a
forever :: !(a b) -> a c | Monad a
forever a = let a` = a >>| a` in a`
join :: (a (a b)) -> a b | Monad a
join :: !(a (a b)) -> a b | Monad a
join x = x >>= id
zipWithM :: (.a -> .(.b -> c d)) ![.a] [.b] -> c [d] | Monad c
......@@ -49,19 +49,19 @@ replicateM n x = sequence (replicate n x)
(<=<) infixr 1 :: u:((a -> b c) -> v:(w:(.d -> b a) -> x:(.d -> b c))) | Monad b, [v <= u,x <= w]
(<=<) = flip (>=>)
liftM :: (a -> b) (c a) -> c b | Monad c
liftM :: (a -> b) !(c a) -> c b | Monad c
liftM f m1 = m1 >>= \x1 -> lift (f x1)
liftM2 :: (a -> .(b -> c)) (d a) (d b) -> d c | Monad d
liftM2 :: (a -> .(b -> c)) !(d a) (d b) -> d c | Monad d
liftM2 f m1 m2 = m1 >>= \x1 -> m2 >>= \x2 -> lift (f x1 x2)
liftM3 :: (a -> .(b -> .(c -> d))) (e a) (e b) (e c) -> e d | Monad e
liftM3 :: (a -> .(b -> .(c -> d))) !(e a) (e b) (e c) -> e d | Monad e
liftM3 f m1 m2 m3 = m1 >>= \x1 -> m2 >>= \x2 -> m3 >>= \x3 -> lift (f x1 x2 x3)
liftM4 :: (a -> .(b -> .(c -> .(d -> e)))) (f a) (f b) (f c) (f d) -> f e | Monad f
liftM4 :: (a -> .(b -> .(c -> .(d -> e)))) !(f a) (f b) (f c) (f d) -> f e | Monad f
liftM4 f m1 m2 m3 m4 = m1 >>= \x1 -> m2 >>= \x2 -> m3 >>= \x3 -> m4 >>= \x4 -> lift (f x1 x2 x3 x4)
liftM5 :: (a -> .(b -> .(c -> .(d -> .(e -> f))))) (g a) (g b) (g c) (g d) (g e) -> g f | Monad g
liftM5 :: (a -> .(b -> .(c -> .(d -> .(e -> f))))) !(g a) (g b) (g c) (g d) (g e) -> g f | Monad g
liftM5 f m1 m2 m3 m4 m5 = m1 >>= \x1 -> m2 >>= \x2 -> m3 >>= \x3 -> m4 >>= \x4 -> m5 >>= \x5 -> lift (f x1 x2 x3 x4 x5)
ap :: u:((a (b -> c)) -> v:((a b) -> a c)) | Monad a, [v <= u]
......
......@@ -27,13 +27,17 @@ instance Foldable (Either a)
instance Traversable (Either a)
instance Bifunctor Either
where
bifmap :: (a -> c) (b -> d) !(Either a b) -> Either c d
first :: (a -> c) !(Either a b) -> Either c b
second :: (b -> d) !(Either a b) -> Either a d
instance Alternative (Either m) | Monoid m
derive gEq Either
either :: .(.a -> .c) .(.b -> .c) !(Either .a .b) -> .c
lefts :: .[Either .a .b] -> .[.a]
rights :: .[Either .a .b] -> .[.b]
fromLeft :: .a (Either .a .b) -> .a
fromRight :: .b (Either .a .b) -> .b
lefts :: !.[Either .a .b] -> .[.a]
rights :: !.[Either .a .b] -> .[.b]
fromLeft :: .a !(Either .a .b) -> .a
fromRight :: .b !(Either .a .b) -> .b
......@@ -73,9 +73,14 @@ where
instance Bifunctor Either
where
bifmap :: (a -> c) (b -> d) !(Either a b) -> Either c d
bifmap f _ (Left a) = Left (f a)
bifmap _ g (Right b) = Right (g b)
first :: (a -> c) !(Either a b) -> Either c b
first f d = bifmap f id d
second :: (b -> d) !(Either a b) -> Either a d
second g d = bifmap id g d
instance Alternative (Either m) | Monoid m
......@@ -89,14 +94,14 @@ either :: .(.a -> .c) .(.b -> .c) !(Either .a .b) -> .c
either f _ (Left x) = f x
either _ g (Right y) = g y
lefts :: .[Either .a .b] -> .[.a]
lefts :: !.[Either .a .b] -> .[.a]
lefts l = [l\\(Left l)<-l]
rights :: .[Either .a .b] -> .[.b]
rights :: !.[Either .a .b] -> .[.b]
rights l = [l\\(Right l)<-l]
fromLeft :: .a (Either .a .b) -> .a
fromLeft :: .a !(Either .a .b) -> .a
fromLeft a e = either id (const a) e
fromRight :: .b (Either .a .b) -> .b
fromRight :: .b !(Either .a .b) -> .b
fromRight a e = either (const a) id e
......@@ -94,19 +94,19 @@ instance Foldable (Const m)
* Monadic fold over the elements of a structure, associating to the right,
* i.e. from right to left.
*/
foldrM :: (a b -> m b) b (t a) -> m b | Foldable t & Monad m
foldrM :: (a b -> m b) b !(t a) -> m b | Foldable t & Monad m
/**
* Monadic fold over the elements of a structure, associating to the left, i.e.
* from left to right.
*/
foldlM :: (b a -> m b) b (t a) -> m b | Foldable t & Monad m
foldlM :: (b a -> m b) b !(t a) -> m b | Foldable t & Monad m
/**
* Map each element of a structure to an action, evaluate these actions from
* left to right, and ignore the results.
*/
traverse_ :: (a -> f b) (t a) -> f () | Foldable t & *> f
traverse_ :: (a -> f b) !(t a) -> f () | Foldable t & *> f
/**
* `for_` is {{`traverse_`}} with its arguments flipped.
......@@ -118,7 +118,7 @@ for_ :== flip traverse_
* Map each element of a structure to a monadic action, evaluate these actions
* from left to right, and ignore the results.
*/
mapM_ :: (a -> m b) (t a) -> m () | Foldable t & Monad m
mapM_ :: (a -> m b) !(t a) -> m () | Foldable t & Monad m
/**
* `forM_` is {{`mapM_`}} with its arguments flipped.
......@@ -130,7 +130,7 @@ forM_ :== flip mapM_
* Evaluate each action in the structure from left to right, and ignore the
* results.
*/
sequenceA_ :: (t (f a)) -> f () | Foldable t & *> f
sequenceA_ :: !(t (f a)) -> f () | Foldable t & *> f
/**
* Evaluate each monadic action in the structure from left to right, and ignore
......@@ -166,83 +166,83 @@ build g :== g (\x xs -> [x:xs]) []
/**
* The concatenation of all the elements of a container of lists.
*/
concat :: (t [a]) -> [a] | Foldable t
concat :: !(t [a]) -> [a] | Foldable t
/**
* Map a function over all the elements of a container and concatenate the
* resulting lists.
*/
concatMap :: (a -> [b]) (t a) -> [b] | Foldable t
concatMap :: (a -> [b]) !(t a) -> [b] | Foldable t
/**
* `and` returns the conjunction of a container of {{`Bool`}}s. For the result
* to be {{`True`}}, the container must be finite; {{`False`}}, however,
* results from a {{`False`}} value finitely far from the left end.
*/
and :: (t Bool) -> Bool | Foldable t
and :: !(t Bool) -> Bool | Foldable t
/**
* `or` returns the disjunction of a container of {{`Bool`}}s. For the result
* to be {{`False`}}, the container must be finite; {{`True`}}, however,
* results from a {{`True`}} value finitely far from the left end.
*/
or :: (t Bool) -> Bool | Foldable t
or :: !(t Bool) -> Bool | Foldable t
/**
* Determines whether any element of the structure satisfies the predicate.
*/
any :: (a -> Bool) (t a) -> Bool | Foldable t
any :: (a -> Bool) !(t a) -> Bool | Foldable t
/**
* Determines whether all elements of the structure satisfy the predicate.
*/
all :: (a -> Bool) (t a) -> Bool | Foldable t
all :: (a -> Bool) !(t a) -> Bool | Foldable t
/**
* The `sum` function computes the sum of the numbers of a structure.
*/
sum :: (t a) -> a | Foldable t & + a & zero a
sum :: !(t a) -> a | Foldable t & + a & zero a
/**
* The `product` function computes the product of the numbers of a structure.
*/
product :: (t a) -> a | Foldable t & * a & one a
product :: !(t a) -> a | Foldable t & * a & one a
/**
* The largest element of a non-empty structure.
*/
maximum :: (t a) -> a | Foldable t & Ord a
maximum :: !(t a) -> a | Foldable t & Ord a
/**
* The largest element of a non-empty structure with respect to the given
* lesser-than function.
*/
maximumBy :: (a a -> Bool) (t a) -> a | Foldable t
maximumBy :: (a a -> Bool) !(t a) -> a | Foldable t
/**
* The least element of a non-empty structure.
*/
minimum :: (t a) -> a | Foldable t & Ord a
minimum :: !(t a) -> a | Foldable t & Ord a
/**
* The least element of a non-empty structure with respect to the given
* lesser-than function.
*/
minimumBy :: (a a -> Bool) (t a) -> a | Foldable t
minimumBy :: (a a -> Bool) !(t a) -> a | Foldable t
/**
* Does the element occur in the structure?
*/
elem :: a (t a) -> Bool | Foldable t & == a
elem :: a !(t a) -> Bool | Foldable t & == a
/**
* `notElem` is the negation of {{`elem`}}.
*/
notElem :: a (t a) -> Bool | Foldable t & == a
notElem :: a !(t a) -> Bool | Foldable t & == a
/**
* The `find` function takes a predicate and a structure and returns the
* leftmost element of the structure matching the predicate, or {{`Nothing`}}
* if there is no such element.
*/
find :: (a -> Bool) (t a) -> Maybe a | Foldable t
find :: (a -> Bool) !(t a) -> Maybe a | Foldable t
......@@ -38,66 +38,66 @@ instance Foldable (Const m) where
mf Nothing y = Just y
mf (Just x) y = Just (f x y)
foldrM :: (a b -> m b) b (t a) -> m b | Foldable t & Monad m
foldrM :: (a b -> m b) b !(t a) -> m b | Foldable t & Monad m
foldrM f z0 xs = foldl f` pure xs z0
where f` k x z = f x z >>= k
foldlM :: (b a -> m b) b (t a) -> m b | Foldable t & Monad m
foldlM :: (b a -> m b) b !(t a) -> m b | Foldable t & Monad m
foldlM f z0 xs = foldr f` pure xs z0
where f` x k z = f z x >>= k
traverse_ :: (a -> f b) (t a) -> f () | Foldable t & *> f
traverse_ :: (a -> f b) !(t a) -> f () | Foldable t & *> f
traverse_ f x = foldr ((*>) o f) (pure ()) x
mapM_ :: (a -> m b) (t a) -> m () | Foldable t & Monad m
mapM_ :: (a -> m b) !(t a) -> m () | Foldable t & Monad m
mapM_ f x = foldr ((\ma mb -> ma >>= \_ -> mb) o f) (pure ()) x
sequenceA_ :: (t (f a)) -> f () | Foldable t & *> f
sequenceA_ :: !(t (f a)) -> f () | Foldable t & *> f
sequenceA_ x = foldr (*>) (pure ()) x
concat :: (t [a]) -> [a] | Foldable t
concat :: !(t [a]) -> [a] | Foldable t
concat x = fold x
concatMap :: (a -> [b]) (t a) -> [b] | Foldable t
concatMap :: (a -> [b]) !(t a) -> [b] | Foldable t
concatMap f x = foldMap f x
and :: (t Bool) -> Bool | Foldable t
and :: !(t Bool) -> Bool | Foldable t
and x = getAll (foldMap All x)
or :: (t Bool) -> Bool | Foldable t
or :: !(t Bool) -> Bool | Foldable t
or x = getAny (foldMap Any x)
any :: (a -> Bool) (t a) -> Bool | Foldable t
any :: (a -> Bool) !(t a) -> Bool | Foldable t
any p x = getAny (foldMap (Any o p) x)
all :: (a -> Bool) (t a) -> Bool | Foldable t
all :: (a -> Bool) !(t a) -> Bool | Foldable t
all p x = getAll (foldMap (All o p) x)
sum :: (t a) -> a | Foldable t & + a & zero a
sum :: !(t a) -> a | Foldable t & + a & zero a
sum x = getSum (foldMap Sum x)
product :: (t a) -> a | Foldable t & * a & one a
product :: !(t a) -> a | Foldable t & * a & one a
product x = getProduct (foldMap Product x)
maximum :: (t a) -> a | Foldable t & Ord a
maximum :: !(t a) -> a | Foldable t & Ord a
maximum x = foldr1 max x
maximumBy :: (a a -> Bool) (t a) -> a | Foldable t
maximumBy :: (a a -> Bool) !(t a) -> a | Foldable t
maximumBy cmp x = foldr1 max` x
where max` x y = if (cmp x y) y x
minimum :: (t a) -> a | Foldable t & Ord a
minimum :: !(t a) -> a | Foldable t & Ord a
minimum x = foldr1 min x
minimumBy :: (a a -> Bool) (t a) -> a | Foldable t
minimumBy :: (a a -> Bool) !(t a) -> a | Foldable t
minimumBy cmp x = foldr1 min` x
where min` x y = if (cmp x y) x y
elem :: a (t a) -> Bool | Foldable t & == a
elem :: a !(t a) -> Bool | Foldable t & == a
elem x y = any (\z -> x == z) y
notElem :: a (t a) -> Bool | Foldable t & == a
notElem :: a !(t a) -> Bool | Foldable t & == a
notElem x y = not (elem x y)
find :: (a -> Bool) (t a) -> Maybe a | Foldable t
find :: (a -> Bool) !(t a) -> Maybe a | Foldable t
find p x = listToMaybe (concatMap (\x -> if (p x) [x] []) x)
......@@ -6,7 +6,7 @@ from Control.Monad import class Monad
from Data.Monoid import class Semigroup, class Monoid
instance Functor ((->) r)
instance pure ((->) r)
instance pure ((->) r) where pure :: !a -> b -> a
instance <*> ((->) r)
instance Monad ((->) r)
......
......@@ -12,7 +12,8 @@ where
instance pure ((->) r)
where
pure x = const x
pure :: !a -> b -> a
pure x = const x
instance <*> ((->) r)
where
......
......@@ -438,6 +438,8 @@ delList xs m :== 'StdList'.foldr (\k m -> del k m) m xs
putList xs m :== union (fromList xs) m
instance Functor (Map k)
where
fmap :: !(a -> b) !(Map k a) -> Map k b
difference :: !(Map k a) !(Map k b) -> Map k a | < k
mapWithKey :: !(k a -> b) !(Map k a) -> Map k b
......
......@@ -1922,8 +1922,10 @@ instance < (Map k v) | Ord k & Ord v where
////////////////////////////////////////////////////////////////////
// Functor
////////////////////////////////////////////////////////////////////
instance Functor (Map k) where
fmap f m = map f m
instance Functor (Map k)
where
fmap :: !(a -> b) !(Map k a) -> Map k b
fmap f m = map f m
// TODO
//instance Traversable (Map k) where
......
......@@ -76,3 +76,5 @@ instance <*> (MaybeT m) | Monad m
instance Alternative (MaybeT m) | Monad m
instance Monad (MaybeT m) | Monad m
instance MonadTrans MaybeT
where
liftT :: !(a b) -> MaybeT a b | Monad a
......@@ -147,5 +147,7 @@ instance Monad (MaybeT m) | Monad m where
Nothing -> return Nothing
Just y -> runMaybeT $ f y
instance MonadTrans MaybeT where
instance MonadTrans MaybeT
where
liftT :: !(a b) -> MaybeT a b | Monad a
liftT m = MaybeT $ liftM Just m
......@@ -108,9 +108,9 @@ class Traversable t | Functor t & Foldable t where
// and collect the results.
sequence :: !(t (m a)) -> m (t a) | Monad m
for :: (t a) (a -> f b) -> f (t b) | Traversable t & Applicative f
forM :: (t a) (a -> m b) -> m (t b) | Traversable t & Monad m
mapAccumL :: (b -> (*s -> *(c, *s))) (t b) *s -> *(t c, *s) | Traversable t
mapAccumR :: (b -> (*s -> *(c, *s))) (t b) *s -> *(t c, *s) | Traversable t
fmapDefault :: (a -> b) (t a) -> t b | Traversable t
foldMapDefault :: (a -> m) (t a) -> m | Traversable t & Monoid m
for :: !(t a) (a -> f b) -> f (t b) | Traversable t & Applicative f
forM :: !(t a) (a -> m b) -> m (t b) | Traversable t & Monad m
mapAccumL :: (b -> (*s -> *(c, *s))) !(t b) *s -> *(t c, *s) | Traversable t
mapAccumR :: (b -> (*s -> *(c, *s))) !(t b) *s -> *(t c, *s) | Traversable t
fmapDefault :: (a -> b) !(t a) -> t b | Traversable t
foldMapDefault :: (a -> m) !(t a) -> m | Traversable t & Monoid m
......@@ -20,11 +20,11 @@ from StdFunc import o, id, flip
// general functions
// 'for' is 'traverse' with its arguments flipped.
for :: (t a) (a -> f b) -> f (t b) | Traversable t & Applicative f
for :: !(t a) (a -> f b) -> f (t b) | Traversable t & Applicative f
for x f = flip traverse x f
// 'forM' is 'mapM' with its arguments flipped.
forM :: (t a) (a -> m b) -> m (t b) | Traversable t & Monad m
forM :: !(t a) (a -> m b) -> m (t b) | Traversable t & Monad m
forM x f = flip mapM x f
/// left-to-right state transformer
......@@ -56,7 +56,7 @@ where
// and 'foldl'; it applies a function to each element of a structure,
// passing an accumulating parameter from left to right, and returning
// a final value of this accumulator together with the new structure.
mapAccumL :: (b -> (*s -> *(c, *s))) (t b) *s -> *(t c, *s) | Traversable t
mapAccumL :: (b -> (*s -> *(c, *s))) !(t b) *s -> *(t c, *s) | Traversable t
mapAccumL f t s = runStateL (traverse (StateL o f) t) s
// right-to-left state transformer
......@@ -86,19 +86,19 @@ where
// and 'foldr'; it applies a function to each element of a structure,
// passing an accumulating parameter from right to left, and returning
// a final value of this accumulator together with the new structure.
mapAccumR :: (b -> (*s -> *(c, *s))) (t b) *s -> *(t c, *s) | Traversable t
mapAccumR :: (b -> (*s -> *(c, *s))) !(t b) *s -> *(t c, *s) | Traversable t
mapAccumR f t s = runStateR (traverse (StateR o f) t) s
// This function may be used as a value for `fmap` in a `Functor`
// instance, provided that 'traverse' is defined. (Using
// `fmapDefault` with a `Traversable` instance defined only by
// 'sequenceA' will result in infinite recursion.)
fmapDefault :: (a -> b) (t a) -> t b | Traversable t
fmapDefault :: (a -> b) !(t a) -> t b | Traversable t
fmapDefault f x = getId (traverse (Id o f) x)
// This function may be used as a value for `Data.Foldable.foldMap`
// in a `Foldable` instance.
foldMapDefault :: (a -> m) (t a) -> m | Traversable t & Monoid m
foldMapDefault :: (a -> m) !(t a) -> m | Traversable t & Monoid m
foldMapDefault f x = getConst (traverse (Const o f) x)
// local instances
......
......@@ -157,4 +157,4 @@ instance + String
* This is a simple wrapper around the {{`+++`}} instance for `String` which
* first applies {{`toString`}} to both its parameters.
*/
(<+) infixr 5 :: a b -> String | toString a & toString b
(<+) infixr 5 :: !a !b -> String | toString a & toString b
......@@ -248,5 +248,5 @@ instance + String
where
(+) s1 s2 = s1 +++ s2
(<+) infixr 5 :: a b -> String | toString a & toString b
(<+) infixr 5 :: !a !b -> String | toString a & toString b
(<+) x y = toString x + toString y
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment