Copyright | (c) gspia 2020- |
---|---|
License | BSD |
Maintainer | gspia |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Fcf.Control.Monad
Synopsis
- data Return :: a -> Exp (m a)
- data (<*>) :: f (a -> Exp b) -> f a -> Exp (f b)
- data Star_ :: (a -> Exp b) -> f a -> Exp (f b)
- data Plus1 :: Nat -> Exp Nat
- data Plus2 :: Nat -> Exp Nat
- data LiftA2 :: (a -> b -> Exp c) -> f a -> f b -> Exp (f c)
- data LiftA2_ :: (a -> b -> Exp c) -> a -> f b -> Exp (f c)
- data (>>=) :: m a -> (a -> Exp (m b)) -> Exp (m b)
- data Plus2M :: Nat -> Exp [Nat]
- data PureXPlusY :: Nat -> Nat -> Exp [Nat]
- data XPlusYs :: Nat -> [Nat] -> Exp [Nat]
- data XsPlusYsMonadic :: [Nat] -> [Nat] -> Exp [Nat]
- data (>>) :: m a -> m b -> Exp (m b)
- data MapM :: (a -> Exp (m b)) -> t a -> Exp (m (t b))
- data ForM :: t a -> (a -> Exp (m b)) -> Exp (m (t b))
- data Traverse :: (a -> Exp (f b)) -> t a -> Exp (f (t b))
- data Cons_f :: (a -> Exp (f b)) -> a -> f [b] -> Exp (f [b])
- data Id :: a -> Exp a
- data Sequence :: t (f a) -> Exp (f (t a))
Documentation
data Return :: a -> Exp (m a) Source #
Return corresponds to the return
at Monad
or pure
of Applicative.
:kind! Eval (Return 1) :: Maybe Nat :kind! Eval (Return 1) :: Either Symbol Nat
data (<*>) :: f (a -> Exp b) -> f a -> Exp (f b) Source #
(*) corresponds to the value level <*>
. Note that this clashes with
the definition given at Fcf.Combinators.((*)).
Applicatives that we define include:
- Identity
- []
- Maybe
- Either
Example
>>>
:kind! Eval ('Identity Plus2 <*> 'Identity 5)
Eval ('Identity Plus2 <*> 'Identity 5) :: Identity Nat = 'Identity 7
>>>
:kind! Eval ( (<*>) '[ (Fcf.+) 1, (Fcf.*) 10] '[4,5,6,7])
Eval ( (<*>) '[ (Fcf.+) 1, (Fcf.*) 10] '[4,5,6,7]) :: [Nat] = '[5, 6, 7, 8, 40, 50, 60, 70]>>>
:kind! Eval ( (<*>) '[ (Fcf.+) 1, (Fcf.*) 10] '[])
Eval ( (<*>) '[ (Fcf.+) 1, (Fcf.*) 10] '[]) :: [Nat] = '[]>>>
:kind! Eval ( (<*>) '[] '[4,5,6,7])
Eval ( (<*>) '[] '[4,5,6,7]) :: [b] = '[]
Instances
type Eval ('Identity f <*> m :: Identity b -> Type) Source # | |
type Eval ('Node f tfs <*> 'Node x txs :: Tree b -> Type) Source # | |
type Eval ('Just f <*> m :: Maybe b -> Type) Source # | |
type Eval (('Nothing :: Maybe (a -> Exp b)) <*> _1 :: Maybe b -> Type) Source # | |
type Eval (('[] :: [a -> Exp b]) <*> _1 :: [b] -> Type) Source # | |
Defined in Fcf.Control.Monad | |
type Eval (_1 <*> ('[] :: [a]) :: [b] -> Type) Source # | |
Defined in Fcf.Control.Monad | |
type Eval ((f ': fs) <*> (a2 ': as) :: [b] -> Type) Source # | |
type Eval (('Left e :: Either a1 (a2 -> Exp b)) <*> _1 :: Either a1 b -> Type) Source # | |
type Eval (('Right f :: Either a2 (a1 -> Exp b)) <*> m :: Either a2 b -> Type) Source # | |
data Star_ :: (a -> Exp b) -> f a -> Exp (f b) Source #
Helper for the [] applicative instance.
data LiftA2 :: (a -> b -> Exp c) -> f a -> f b -> Exp (f c) Source #
Type level LiftA2.
Example
>>>
:kind! Eval (LiftA2 (Fcf.+) '[1,2] '[3,4])
Eval (LiftA2 (Fcf.+) '[1,2] '[3,4]) :: [Nat] = '[4, 5, 5, 6]
Instances
type Eval (LiftA2 f ('Just a3) ('Just b2) :: Maybe a2 -> Type) Source # | |
type Eval (LiftA2 f ('Nothing :: Maybe a) _1 :: Maybe c -> Type) Source # | |
type Eval (LiftA2 f _1 ('Nothing :: Maybe b) :: Maybe c -> Type) Source # | |
type Eval (LiftA2 f ('[] :: [a]) _1 :: [c] -> Type) Source # | |
Defined in Fcf.Control.Monad | |
type Eval (LiftA2 f (a3 ': as) (b ': bs) :: [c] -> Type) Source # | |
type Eval (LiftA2 f (a2 ': as) ('[] :: [b]) :: [c] -> Type) Source # | |
Defined in Fcf.Control.Monad | |
type Eval (LiftA2 f ('Right a3 :: Either a2 a1) ('Right b3 :: Either a2 b1) :: Either a2 b2 -> Type) Source # | |
type Eval (LiftA2 f ('Left e :: Either a2 a1) _1 :: Either a2 c -> Type) Source # | |
type Eval (LiftA2 f ('Right _1 :: Either a2 a1) ('Left e :: Either a2 b) :: Either a2 c -> Type) Source # | |
data LiftA2_ :: (a -> b -> Exp c) -> a -> f b -> Exp (f c) Source #
data (>>=) :: m a -> (a -> Exp (m b)) -> Exp (m b) Source #
Type level Bind corresponding to the value level bind >>=
operator.
Note that name (>>=) clashes with the definition given at
Fcf.Combinators.(>>=). (It doesn't export it yet, though.)
Monads that we define include:
- Identity
- []
- Maybe
- Either
Example
Example: double the length of the input list and increase the numbers at the same time.
>>>
:kind! Eval ('[5,6,7] >>= Plus2M)
Eval ('[5,6,7] >>= Plus2M) :: [Nat] = '[7, 8, 8, 9, 9, 10]
>>>
:kind! Eval (XsPlusYsMonadic '[1,2,3] '[4,5,6])
Eval (XsPlusYsMonadic '[1,2,3] '[4,5,6]) :: [Nat] = '[5, 6, 7, 6, 7, 8, 7, 8, 9]
Instances
type Eval ('Identity a2 >>= f :: Identity b -> Type) Source # | |
type Eval (('Nothing :: Maybe a) >>= f :: Maybe b -> Type) Source # | |
type Eval ('Just a2 >>= f :: Maybe b -> Type) Source # | |
type Eval ((x ': xs) >>= f :: [b] -> Type) Source # | |
type Eval (('[] :: [a]) >>= _1 :: [b] -> Type) Source # | |
Defined in Fcf.Control.Monad | |
type Eval (('Left a3 :: Either a1 a2) >>= _1 :: Either a1 b -> Type) Source # | |
type Eval (('Right a3 :: Either a2 a1) >>= f :: Either a2 b -> Type) Source # | |
data XsPlusYsMonadic :: [Nat] -> [Nat] -> Exp [Nat] Source #
An example implementing
sumM xs ys = do x <- xs y <- ys return (x + y)
or
sumM xs ys = xs >>= (x -> ys >>= (y -> pure (x+y)))
Note the use of helper functions. This is a bit awkward, a type level lambda would be nice.
Instances
type Eval (XsPlusYsMonadic xs ys :: [Nat] -> Type) Source # | |
Defined in Fcf.Control.Monad |
data (>>) :: m a -> m b -> Exp (m b) Source #
Instances
type Eval (('Nothing :: Maybe a) >> b2 :: Maybe b1 -> Type) Source # | |
type Eval ('Just a2 >> b2 :: Maybe b1 -> Type) Source # | |
type Eval (('[] :: [a]) >> _1 :: [b] -> Type) Source # | |
Defined in Fcf.Control.Monad | |
type Eval ((x ': xs) >> b2 :: [b1] -> Type) Source # | |
Defined in Fcf.Control.Monad | |
type Eval (('Left a3 :: Either a1 a2) >> _1 :: Either a1 b -> Type) Source # | |
type Eval (('Right _1 :: Either a2 a1) >> b2 :: Either a2 b1 -> Type) Source # | |
data MapM :: (a -> Exp (m b)) -> t a -> Exp (m (t b)) Source #
MapM
Example
>>>
:kind! Eval (MapM (ConstFn '[ 'True, 'False]) '["a","b","c"])
Eval (MapM (ConstFn '[ 'True, 'False]) '["a","b","c"]) :: [[Bool]] = '[ '[ 'True, 'True, 'True], '[ 'True, 'True, 'False], '[ 'True, 'False, 'True], '[ 'True, 'False, 'False], '[ 'False, 'True, 'True], '[ 'False, 'True, 'False], '[ 'False, 'False, 'True], '[ 'False, 'False, 'False]]
data Traverse :: (a -> Exp (f b)) -> t a -> Exp (f (t b)) Source #
Traverse
Example
>>>
:kind! Eval (Traverse Id '[ '[1,2], '[3,4]])
Eval (Traverse Id '[ '[1,2], '[3,4]]) :: [[Nat]] = '[ '[1, 3], '[1, 4], '[2, 3], '[2, 4]]
Instances
type Eval (Traverse f2 ('Left e :: Either a2 a1) :: f1 (Either a2 b) -> Type) Source # | |
type Eval (Traverse f2 ('Right x :: Either a3 a1) :: f1 (Either a3 a2) -> Type) Source # | |
type Eval (Traverse f2 ('Node x ts) :: f1 (Tree b) -> Type) Source # | |
type Eval (Traverse f2 ('Just x) :: f1 (Maybe a2) -> Type) Source # | |
type Eval (Traverse f2 ('Nothing :: Maybe a) :: f1 (Maybe b) -> Type) Source # | |
type Eval (Traverse f2 lst :: f1 [b] -> Type) Source # | |
data Sequence :: t (f a) -> Exp (f (t a)) Source #
Sequence
Example
>>>
:kind! Eval (Sequence ('Just ('Right 5)))
Eval (Sequence ('Just ('Right 5))) :: Either a (Maybe Nat) = 'Right ('Just 5)
>>>
:kind! Eval (Sequence '[ 'Just 3, 'Just 5, 'Just 7])
Eval (Sequence '[ 'Just 3, 'Just 5, 'Just 7]) :: Maybe [Nat] = 'Just '[3, 5, 7]
>>>
:kind! Eval (Sequence '[ 'Just 3, 'Nothing, 'Just 7])
Eval (Sequence '[ 'Just 3, 'Nothing, 'Just 7]) :: Maybe [Nat] = 'Nothing
>>>
:kind! Eval (Sequence '[ '[1,2], '[3,4]])
Eval (Sequence '[ '[1,2], '[3,4]]) :: [[Nat]] = '[ '[1, 3], '[1, 4], '[2, 3], '[2, 4]]