Verified Commit b67d7c50 authored by Camil Staps's avatar Camil Staps 🙂

Add some strictness annotations

parent ec7a8e20
Pipeline #16002 passed with stage
in 1 minute and 13 seconds
......@@ -35,29 +35,45 @@ instance Functor (WrappedMonad m) | Monad m
instance pure (Const m) | Monoid m
instance pure (WrappedMonad m) | pure m
instance <*> (Const m) | Monoid m
where
(<*>) :: !(Const m (a -> b)) !(Const m a) -> Const m b | Monoid m
instance <*> (WrappedMonad m) | Monad m
where
(<*>) :: !(WrappedMonad m (a -> b)) !(WrappedMonad m a) -> WrappedMonad m b | Monad m
instance Monad (WrappedMonad m) | Monad m
instance Alternative (WrappedMonad m) | MonadPlus m
where
(<|>) :: !(WrappedMonad m a) !(WrappedMonad m a) -> WrappedMonad m a | MonadPlus m
instance Semigroup (Const a b) | Semigroup a
where
mappend :: !(Const a b) !(Const a b) -> Const a b | Semigroup a
instance Monoid (Const a b) | Monoid a
some :: (f a) -> f [a] | Alternative f
some :: !(f a) -> f [a] | Alternative f
special f=[]; f=Maybe
many :: (f a) -> f [a] | Alternative f
many :: !(f a) -> f [a] | Alternative f
special f=[]; f=Maybe
(<**>) infixl 4 :: (f a) (f (a -> b)) -> f b | Applicative f
(<**>) infixl 4 :: !(f a) (f (a -> b)) -> f b | Applicative f
special f=[]; f=Maybe
lift :: a -> f a | pure f
special f=[]; f=Maybe
liftA :: (a -> b) (f a) -> f b | Applicative f
special f=[]; f=Maybe
liftA2 :: (a b -> c) (f a) (f b) -> f c | Applicative f
liftA2 :: (a b -> c) !(f a) (f b) -> f c | Applicative f
special f=[]; f=Maybe
liftA3 :: (a b c -> d) (f a) (f b) (f c) -> f d | Applicative f
liftA3 :: (a b c -> d) !(f a) (f b) (f c) -> f d | Applicative f
special f=[]; f=Maybe
optional :: (f a) -> f (Maybe a) | Alternative f
optional :: !(f a) -> f (Maybe a) | Alternative f
special f=[]; f=Maybe
/**
* Conditional execution of Applicative expressions. For example,
......
......@@ -11,8 +11,10 @@ getConst (Const x) = x
instance Functor (Const m) where
fmap _ (Const v) = Const v
instance Semigroup (Const a b) | Semigroup a where
mappend (Const a) (Const b) = Const (mappend a b)
instance Semigroup (Const a b) | Semigroup a
where
mappend :: !(Const a b) !(Const a b) -> Const a b | Semigroup a
mappend (Const a) (Const b) = Const (mappend a b)
instance Monoid (Const a b) | Monoid a where
mempty = Const mempty
......@@ -23,6 +25,7 @@ where
instance <*> (Const m) | Monoid m
where
(<*>) :: !(Const m (a -> b)) !(Const m a) -> Const m b | Monoid m
(<*>) (Const f) (Const v) = Const (mappend f v)
unwrapMonad :: !(WrappedMonad m a) -> m a
......@@ -37,26 +40,29 @@ where
instance <*> (WrappedMonad m) | Monad m
where
(<*>) :: !(WrappedMonad m (a -> b)) !(WrappedMonad m a) -> WrappedMonad m b | Monad m
(<*>) (WrapMonad f) (WrapMonad v) = WrapMonad (ap f v)
instance Monad (WrappedMonad m) | Monad m where
bind a f = WrapMonad (unwrapMonad a >>= unwrapMonad o f)
instance Alternative (WrappedMonad m) | MonadPlus m where
empty = WrapMonad mzero
(<|>) (WrapMonad u) (WrapMonad v) = WrapMonad (mplus u v)
instance Alternative (WrappedMonad m) | MonadPlus m
where
empty = WrapMonad mzero
(<|>) :: !(WrappedMonad m a) !(WrappedMonad m a) -> WrappedMonad m a | MonadPlus m
(<|>) (WrapMonad u) (WrapMonad v) = WrapMonad (mplus u v)
some :: (f a) -> f [a] | Alternative f
some :: !(f a) -> f [a] | Alternative f
some v = some_v
where many_v = some_v <|> lift []
some_v = (\x xs -> [x:xs]) <$> v <*> many_v
many :: (f a) -> f [a] | Alternative f
many :: !(f a) -> f [a] | Alternative f
many v = many_v
where many_v = some_v <|> lift []
some_v = (\x xs -> [x:xs]) <$> v <*> many_v
(<**>) infixl 4 :: (f a) (f (a -> b)) -> f b | Applicative f
(<**>) infixl 4 :: !(f a) (f (a -> b)) -> f b | Applicative f
(<**>) fa fab = liftA2 (flip ($)) fa fab
lift :: a -> f a | pure f
......@@ -65,11 +71,11 @@ lift x = pure x
liftA :: (a -> b) (f a) -> f b | Applicative f
liftA f a = lift f <*> a
liftA2 :: (a b -> c) (f a) (f b) -> f c | Applicative f
liftA2 :: (a b -> c) !(f a) (f b) -> f c | Applicative f
liftA2 f a b = f <$> a <*> b
liftA3 :: (a b c -> d) (f a) (f b) (f c) -> f d | Applicative f
liftA3 :: (a b c -> d) !(f a) (f b) (f c) -> f d | Applicative f
liftA3 f a b c = f <$> a <*> b <*> c
optional :: (f a) -> f (Maybe a) | Alternative f
optional :: !(f a) -> f (Maybe a) | Alternative f
optional v = (Just <$> v) <|> (lift Nothing)
......@@ -24,6 +24,8 @@ instance Monad Maybe
instance MonadPlus Maybe
instance Semigroup (Maybe a) | Semigroup a
where
mappend :: !(Maybe a) !(Maybe a) -> Maybe a | Semigroup a
instance Monoid (Maybe a)
instance Foldable Maybe
instance Traversable Maybe
......
......@@ -51,6 +51,7 @@ where
instance Semigroup (Maybe a) | Semigroup a
where
mappend :: !(Maybe a) !(Maybe a) -> Maybe a | Semigroup a
mappend Nothing m = m
mappend m Nothing = m
mappend (Just m1) (Just m2) = Just (mappend m1 m2)
......
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