Skip to content

Commit

Permalink
NonEmpty as a pure carrier for Choose.
Browse files Browse the repository at this point in the history
In keeping with #206, this offers a solo `Carrier` instance for
`NonEmpty` lists over the `Choose` effects. Because `NonEmpty` is now
in `base`, this doesn't add new dependencies, and nicely rounds out
the carrier definition of `[]` for `NonDet` and `Maybe` for `Empty`.
  • Loading branch information
patrickt committed Oct 6, 2019
1 parent 86cd3c4 commit 6713d8c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Control/Carrier/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import Control.Effect.Reader (Reader(..))
import Control.Effect.Sum ((:+:)(..))
import Control.Effect.Writer (Writer(..))
import Control.Monad ((<=<))
import Data.List.NonEmpty (NonEmpty)

-- | The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the 'eff' method.
class (HFunctor sig, Monad m) => Carrier sig m | m -> sig where
-- | Construct a value in the carrier for an effect signature (typically a sum of a handled effect and any remaining effects).
eff :: sig m a -> m a


instance Carrier Choose NonEmpty where
eff (Choose m) = m True <> m False

instance Carrier Empty Maybe where
eff Empty = Nothing

Expand Down

0 comments on commit 6713d8c

Please sign in to comment.