[ANN] fcf-containers 0.7.0 with early support for applicative and monadic computations

Please do find version 0.7.0 of fcf-containers at hackage/fcf-container and at github/fcf-containers.

Fcf-containers builds on defunctionalization techniques introduced at hackage/first-class-families and fcf-containers adds helpers to do type level (or compile time) computations.

This release, in particular, adds early trials to do applicative and monadic computations at type level. Please do check the source for numerous examples.

Here are couple of examples:

> :l Fcf.Control.Monad
[1 of 1] Compiling Fcf.Control.Monad ( src/Fcf/Control/Monad.hs, interpreted )
Ok, one module loaded.
> :kind! Eval (MapM (ConstFn '[ 'True, 'False]) '[1,2,3])
Eval (MapM (ConstFn '[ 'True, 'False]) '[1,2,3]) :: [[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]]
> :kind! Eval (Sequence '[ '[1,2], '[3,4]])
Eval (Sequence '[ '[1,2], '[3,4]]) :: [[Nat]]
= '[ '[1, 3], '[1, 4], '[2, 3], '[2, 4]]
> :kind! Eval (Sequence '[ 'Just "a", 'Just "b"])
Eval (Sequence '[ 'Just "a", 'Just "b"]) :: Maybe
                                              [GHC.Types.Symbol]
= 'Just '["a", "b"]

Occasionally, the code will be very clumsy. The examples contain one way to compute

sumM xs ys = xs >>= (\x -> ys >>= (\y -> pure (x+y)))

at type level. Once the type-level lambda lands into ghc, the clumsiness will go away… :slight_smile: (thou probably this whole lib is not needed anymore when that happens).

This release did not yet start to take into account the goodies given with ghc 9.2.2. I’m hoping to re-write the “text” module for those much better symbol manipulations more or less soon(ish).

2 Likes