Skip to content

Commit b582f8d

Browse files
committed
Add applicative ListT transformer
1 parent 3582ba8 commit b582f8d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

monad-bayes.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ common test-deps
8686
library
8787
import: deps
8888
exposed-modules:
89+
Control.Applicative.List
8990
Control.Monad.Bayes.Class
9091
Control.Monad.Bayes.Density.Free
9192
Control.Monad.Bayes.Density.State
@@ -114,8 +115,11 @@ library
114115
other-modules: Control.Monad.Bayes.Traced.Common
115116
default-language: Haskell2010
116117
default-extensions:
118+
ApplicativeDo
117119
BlockArguments
120+
DerivingStrategies
118121
FlexibleContexts
122+
GeneralizedNewtypeDeriving
119123
ImportQualifiedPost
120124
LambdaCase
121125
OverloadedStrings

src/Control/Applicative/List.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Control.Applicative.List where
2+
3+
-- base
4+
5+
import Control.Applicative
6+
import Data.Functor.Compose
7+
8+
-- | _Applicative_ transformer adding a list/nondeterminism/choice effect.
9+
-- It is not a valid monad transformer, but it is a valid 'Applicative'.
10+
newtype ListT m a = ListT {getListT :: Compose [] m a}
11+
deriving newtype (Functor, Applicative, Alternative)
12+
13+
lift :: m a -> ListT m a
14+
lift = ListT . Compose . pure
15+
16+
runListT :: ListT m a -> [m a]
17+
runListT = getCompose . getListT

0 commit comments

Comments
 (0)