HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulefcf-containers-0.8.2Haskell2010

Fcf.Control.Monad

Fcf.Control.Monad

  • 27 types
Example2 expressions
import qualified GHC.TypeLits as TLimport qualified Fcf.Combinators as C
datadata Return (b :: a) (c :: m a)
#

Return corresponds to the return at Monad or pure of Applicative.

:kind! Eval (Return 1) :: Maybe Nat :kind! Eval (Return 1) :: Either Symbol Nat

Instances8Eval, …
  • type Eval (Return a) = '(MEmpty, MEmpty, MEmpty, a)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval (Return a) = '(MEmpty, MEmpty, a)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval (Return a) = '(MEmpty, a)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval (Return a) = '[a]Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval (Return a2) = 'Node a2 '[]Defined in fcf-containers-0.8.2 · Fcf.Data.Tree
  • type Eval (Return a2) = 'Right a2Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval (Return a2) = 'Identity a2Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval (Return a2) = 'Just a2Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata (<*>) (c :: f (a -> Exp b)) (d :: f a) (e :: f b)
#

(*) 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
Example1 expression
:kind! Eval ('Identity Plus2 <*> 'Identity 5)Eval ('Identity Plus2 <*> 'Identity 5) :: Identity Natural= 'Identity 7
Example3 expressions
:kind! Eval ( (<*>) '[ (Fcf.+) 1, (Fcf.*) 10] '[4,5,6,7])Eval ( (<*>) '[ (Fcf.+) 1, (Fcf.*) 10] '[4,5,6,7]) :: [Natural]= '[5, 6, 7, 8, 40, 50, 60, 70]:kind! Eval ( (<*>) '[ (Fcf.+) 1, (Fcf.*) 10] '[])Eval ( (<*>) '[ (Fcf.+) 1, (Fcf.*) 10] '[]) :: [Natural]= '[]:kind! Eval ( (<*>) '[] '[4,5,6,7])Eval ( (<*>) '[] '[4,5,6,7]) :: [b]= '[]
Instances12Eval, …
  • type Eval ('Node f tfs <*> 'Node x txs) = 'Node (Eval (f x)) (Eval (Eval (Map (Map f) txs) ++ Eval (Map (StarTx ('Node x txs)) tfs)))Defined in fcf-containers-0.8.2 · Fcf.Data.Tree
  • type Eval ('Left e <*> _1) = 'Left eDefined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('Right f <*> m) = Eval (Map f m)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('Identity f <*> m) = Eval (Map f m)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('Just f <*> m) = Eval (Map f m)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('Nothing <*> _1) = 'NothingDefined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('(a2, b, c, f) <*> '(a', b', c', x)) = '(a2 <> a', b <> b', c <> c', Eval (f x))Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('(a2, b, f) <*> '(a', b', x)) = '(a2 <> a', b <> b', Eval (f x))Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('(u, f) <*> '(v, x)) = '(u <> v, Eval (f x))Defined in fcf-containers-0.8.2 · Fcf.Control.Monad

    For tuples, the Monoid constraint determines how the first values merge. For example, Symbols concatenate:

    Example1 expression
    :kind! Eval ('("hello", (Fcf.+) 15) <*> '("world!", 2002))Eval ('("hello", (Fcf.+) 15) <*> '("world!", 2002)) :: (TL.Symbol,                                                        Natural)= '("helloworld!", 2017)
  • type Eval ('[] <*> _1) = '[]Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ((f ': fs) <*> (a2 ': as)) = Eval (Eval (Star_ f (a2 ': as)) ++ Eval (fs <*> (a2 ': as)))Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval (_1 <*> '[]) = '[]Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata LiftA2 (d :: a -> b -> Exp c) (e :: f a) (g :: f b) (h :: f c)
#

Type level LiftA2.

Example
Example1 expression
:kind! Eval (LiftA2 (Fcf.+) '[1,2] '[3,4])Eval (LiftA2 (Fcf.+) '[1,2] '[3,4]) :: [Natural]= '[4, 5, 5, 6]
Instances1Eval
datadata LiftA3 (e :: a -> b -> c -> Exp d) (g :: f a) (h :: f b) (i :: f c) (j :: f d)
#

Type level LiftA3.

Example
Example1 expression
:kind! Eval (LiftA3 Tuple3 '[1,2] '[3,4] '[5,6])Eval (LiftA3 Tuple3 '[1,2] '[3,4] '[5,6]) :: [(Natural, Natural,                                               Natural)]= '[ '(1, 3, 5), '(1, 3, 6), '(1, 4, 5), '(1, 4, 6), '(2, 3, 5),     '(2, 3, 6), '(2, 4, 5), '(2, 4, 6)]
Example1 expression
:kind! Eval (LiftA3 Tuple3 ('Right 5) ('Right 6) ('Left "fail"))Eval (LiftA3 Tuple3 ('Right 5) ('Right 6) ('Left "fail")) :: Either                                                               TL.Symbol (Natural, Natural, c)= 'Left "fail"
Instances1Eval
datadata LiftA4 (g :: a -> b -> c -> d -> Exp e) (h :: f a) (i :: f b) (j :: f c) (k :: f d) (l :: f e)
#

Type level LiftA4.

Instances1Eval
datadata LiftA5 (h :: a -> b -> c -> d -> e -> Exp g) (i :: f a) (j :: f b) (k :: f c) (l :: f d) (m :: f e) (n :: f g)
#

Type level LiftA5.

Instances1Eval
datadata (>>=) (c :: m a) (d :: a -> Exp (m b)) (e :: m b)
#

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.

Example1 expression
:kind! Eval ('[5,6,7] >>= Plus2M)Eval ('[5,6,7] >>= Plus2M) :: [Natural]= '[7, 8, 8, 9, 9, 10]
Example1 expression
:kind! Eval (XsPlusYsMonadic '[1,2,3] '[4,5,6])Eval (XsPlusYsMonadic '[1,2,3] '[4,5,6]) :: [Natural]= '[5, 6, 7, 6, 7, 8, 7, 8, 9]
Instances10Eval, …
  • type Eval ('Left a3 >>= _1) = 'Left a3Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('Right a3 >>= f) = Eval (f a3)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('Identity a2 >>= f) = Eval (f a2)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('Just a2 >>= f) = Eval (f a2)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('Nothing >>= f) = 'NothingDefined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('(u, a2) >>= k2) = Eval ('(u, Id) <*> Eval (k2 a2))Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('(u, v, a2) >>= k3) = Eval ('(u, v, Id) <*> Eval (k3 a2))Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('(u, v, w, a2) >>= k4) = Eval ('(u, v, w, Id) <*> Eval (k4 a2))Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ('[] >>= _1) = '[]Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval ((x ': xs) >>= f) = Eval ((f @@ x) ++ Eval (xs >>= f))Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata (>>) (c :: m a) (d :: m b) (e :: m b)
#

Type level >>

Example
Example2 expressions
:kind! Eval ( 'Just 1 >> 'Just 2)Eval ( 'Just 1 >> 'Just 2) :: Maybe Natural= 'Just 2:kind! Eval ( 'Nothing >> 'Just 2)Eval ( 'Nothing >> 'Just 2) :: Maybe Natural= 'Nothing
Instances1Eval
datadata MapM (c :: a -> Exp (m b)) (d :: t a) (e :: m (t b))
#

MapM

Example
Example1 expression
: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]]
Instances1Eval
datadata ForM (c :: t a) (d :: a -> Exp (m b)) (e :: m (t b))
#

ForM = Flip MapM

Instances1Eval
  • type Eval (ForM ta f) = Eval (MapM f ta)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata FoldlM (c :: b -> a -> Exp (m b)) (d :: b) (e :: t a) (f :: m b)
#

FoldlM

Example
Example5 expressions
import GHC.TypeLits as TL (Symbol, type (-))data Lambda :: Nat -> Nat -> Exp (Either Symbol Natural)type instance Eval (Lambda a b) = If (Eval (a >= b)) ('Right (a TL.- b)) ('Left "Nat cannot be negative"):kind! Eval (FoldlM Lambda 5 '[1,1,1])Eval (FoldlM Lambda 5 '[1,1,1]) :: Either Symbol Natural= 'Right 2:kind! Eval (FoldlM Lambda 5 '[1,4,1])Eval (FoldlM Lambda 5 '[1,4,1]) :: Either Symbol Natural= 'Left "Nat cannot be negative"
Instances1Eval
datadata Traverse (c :: a -> Exp (f b)) (d :: t a) (e :: f (t b))
#

Traverse

Example
Example1 expression
:kind! Eval (Traverse Id '[ '[1,2], '[3,4]])Eval (Traverse Id '[ '[1,2], '[3,4]]) :: [[Natural]]= '[ '[1, 3], '[1, 4], '[2, 3], '[2, 4]]
Instances7Eval, …
datadata Sequence (b :: t (f a)) (c :: f (t a))
#

Sequence

Example
Example1 expression
:kind! Eval (Sequence ('Just ('Right 5)))Eval (Sequence ('Just ('Right 5))) :: Either a (Maybe Natural)= 'Right ('Just 5)
Example1 expression
:kind! Eval (Sequence '[ 'Just 3, 'Just 5, 'Just 7])Eval (Sequence '[ 'Just 3, 'Just 5, 'Just 7]) :: Maybe [Natural]= 'Just '[3, 5, 7]
Example1 expression
:kind! Eval (Sequence '[ 'Just 3, 'Nothing, 'Just 7])Eval (Sequence '[ 'Just 3, 'Nothing, 'Just 7]) :: Maybe [Natural]= 'Nothing
Example1 expression
:kind! Eval (Sequence '[ '[1,2], '[3,4]])Eval (Sequence '[ '[1,2], '[3,4]]) :: [[Natural]]= '[ '[1, 3], '[1, 4], '[2, 3], '[2, 4]]
Instances1Eval
datadata Id (b :: a) (c :: a)
#

Id function correspondes to term level id-function.

Instances1Eval
  • type Eval (Id a2) = a2Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata App2 (d :: a -> b -> c) (e :: a) (f :: b -> c)
#

Needed by LiftA2 instance to partially apply function

Instances1Eval
  • type Eval (App2 f a2) = f a2Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata App3 (e :: a -> b -> c -> d) (f :: a) (g :: b -> Exp (c -> d))
#

Needed by LiftA3 instance to partially apply function

Instances1Eval
  • type Eval (App3 f a2) = Pure2 f a2Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata App4 (f :: a -> b -> c -> d -> e) (g :: a) (h :: b -> Exp (c -> Exp (d -> e)))
#

Needed by LiftA4 instance to partially apply function

Instances1Eval
  • type Eval (App4 f a3) = App3 (f a3)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata App5 (f :: a -> b -> c -> d -> e -> g) (h :: a) (i :: b -> Exp (c -> Exp (d -> Exp (e -> g))))
#

Needed by LiftA5 instance to partially apply function

Instances1Eval
  • type Eval (App5 f a3) = App4 (f a3)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata Star_ (c :: a -> Exp b) (d :: f a) (e :: f b)
#

Helper for the [] applicative instance.

Instances2Eval
  • type Eval (Star_ _1 '[]) = '[]Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
  • type Eval (Star_ f (a2 ': as)) = Eval (f a2) ': Eval (Star_ f as)Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata ConsHelper (c :: a -> Exp (f b)) (d :: a) (e :: f [b]) (g :: f [b])
#

Helper for [] traverse

Instances1Eval
datadata Plus1 (a :: Nat) (b :: Nat)
#

For Applicative documentation example

Instances1Eval
  • type Eval (Plus1 n) = n + 1Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata Plus2 (a :: Nat) (b :: Nat)
#

For Applicative documentation example

Instances1Eval
  • type Eval (Plus2 n) = n + 2Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata Plus2M (a :: Nat) (b :: [Nat])
#

For the example. Turn an input number to list of two numbers of a bit larger numbers.

Instances1Eval
  • type Eval (Plus2M n) = '[n + 2, n + 3]Defined in fcf-containers-0.8.2 · Fcf.Control.Monad
datadata XsPlusYsMonadic (a :: [Nat]) (b :: [Nat]) (c :: [Nat])
#

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.

Instances1Eval