Skip to content

Commit

Permalink
Merge pull request #30 from masaeedu/jokerchoice
Browse files Browse the repository at this point in the history
Add instances for Joker
  • Loading branch information
garyb authored Aug 21, 2019
2 parents 1de584b + be868fc commit 9b3d014
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Data/Profunctor/Joker.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module Data.Profunctor.Joker where

import Prelude

import Data.Either (Either(..))
import Data.Newtype (class Newtype, un)
import Data.Profunctor (class Profunctor)
import Data.Newtype (class Newtype)
import Data.Profunctor.Choice (class Choice)

-- | Makes a trivial `Profunctor` for a covariant `Functor`.
newtype Joker f a b = Joker (f b)
Expand All @@ -21,5 +23,20 @@ instance functorJoker :: Functor f => Functor (Joker f a) where
instance profunctorJoker :: Functor f => Profunctor (Joker f) where
dimap f g (Joker a) = Joker (map g a)

instance clownJoker :: Functor f => Choice (Joker f) where
left (Joker f) = Joker $ map Left f
right (Joker f) = Joker $ map Right f

instance applyJoker :: Apply f => Apply (Joker f a) where
apply (Joker f) (Joker g) = Joker $ apply f g

instance applicativeJoker :: Applicative f => Applicative (Joker f a) where
pure = Joker <<< pure

instance bindJoker :: Bind f => Bind (Joker f a) where
bind (Joker ma) amb = Joker $ ma >>= (amb >>> un Joker)

instance monadJoker :: Monad m => Monad (Joker m a)

hoistJoker :: forall f g a b. (f ~> g) -> Joker f a b -> Joker g a b
hoistJoker f (Joker a) = Joker (f a)

0 comments on commit 9b3d014

Please sign in to comment.