Skip to content

Commit

Permalink
Add applicative ListT transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
turion committed Dec 31, 2023
1 parent 3582ba8 commit b582f8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions monad-bayes.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ common test-deps
library
import: deps
exposed-modules:
Control.Applicative.List
Control.Monad.Bayes.Class
Control.Monad.Bayes.Density.Free
Control.Monad.Bayes.Density.State
Expand Down Expand Up @@ -114,8 +115,11 @@ library
other-modules: Control.Monad.Bayes.Traced.Common
default-language: Haskell2010
default-extensions:
ApplicativeDo
BlockArguments
DerivingStrategies
FlexibleContexts
GeneralizedNewtypeDeriving
ImportQualifiedPost
LambdaCase
OverloadedStrings
Expand Down
17 changes: 17 additions & 0 deletions src/Control/Applicative/List.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Control.Applicative.List where

-- base

import Control.Applicative
import Data.Functor.Compose

-- | _Applicative_ transformer adding a list/nondeterminism/choice effect.
-- It is not a valid monad transformer, but it is a valid 'Applicative'.
newtype ListT m a = ListT {getListT :: Compose [] m a}
deriving newtype (Functor, Applicative, Alternative)

lift :: m a -> ListT m a
lift = ListT . Compose . pure

runListT :: ListT m a -> [m a]
runListT = getCompose . getListT

0 comments on commit b582f8d

Please sign in to comment.