@@ -11,6 +11,7 @@ import Control.Plus (class Plus, empty)
1111import Data.Distributive (class Distributive , distribute , collect )
1212import Data.Either (Either (..), either )
1313import Data.Functor.Invariant (class Invariant , imap )
14+ import Data.Newtype (class Newtype )
1415import Data.Profunctor (class Profunctor )
1516import Data.Profunctor.Choice (class Choice )
1617import Data.Profunctor.Closed (class Closed )
@@ -22,9 +23,7 @@ import Data.Tuple (Tuple(..))
2223-- | `Star f` is also the Kleisli category for `f`
2324newtype Star f a b = Star (a -> f b )
2425
25- -- | Unwrap a value of type `Star f a b`.
26- unStar :: forall f a b . Star f a b -> a -> f b
27- unStar (Star f) = f
26+ derive instance newtypeStar :: Newtype (Star f a b ) _
2827
2928instance semigroupoidStar :: Bind f => Semigroupoid (Star f ) where
3029 compose (Star f) (Star g) = Star \x -> g x >>= f
@@ -45,7 +44,7 @@ instance applicativeStar :: Applicative f => Applicative (Star f a) where
4544 pure a = Star \_ -> pure a
4645
4746instance bindStar :: Bind f => Bind (Star f a ) where
48- bind (Star m) f = Star \x -> m x >>= \a -> unStar ( f a) x
47+ bind (Star m) f = Star \x -> m x >>= \a -> case f a of Star g -> g x
4948
5049instance monadStar :: Monad f => Monad (Star f a )
5150
@@ -62,7 +61,7 @@ instance monadZeroStar :: MonadZero f => MonadZero (Star f a)
6261instance monadPlusStar :: MonadPlus f => MonadPlus (Star f a )
6362
6463instance distributiveStar :: Distributive f => Distributive (Star f a ) where
65- distribute f = Star \a -> collect ((_ $ a) <<< unStar ) f
64+ distribute f = Star \a -> collect (\( Star g) -> g a ) f
6665 collect f = distribute <<< map f
6766
6867instance profunctorStar :: Functor f => Profunctor (Star f ) where
0 commit comments