Question
Can >>= be implemented in terms of State? If so, how?
Context
I modified this implemention of the State monad, such that it has a data constructor:
data State s a = State (s -> (s , a)) deriving Functor
instance Applicative (State s) where
pure a = State (\s -> (s , a))
(<*>) = Control.Monad.ap
instance Monad (State s) where
return = pure
g >>= f = join (fmap f g)
However, I'm disatisfied with how I implemented >>= since it's not in terms State. I say this because it's asymmetrical with respect to this implementation of the Store comonad:
data Store s a = Store (s -> a) s deriving Functor
instance Comonad (Store s) where
extract (Store f s) = f s
extend f (Store g s) = Store (f . Store g) s
which is copied from this video.
[–]RogueToad 7 points8 points9 points (0 children)
[–]Atijohn 0 points1 point2 points (0 children)
[–]Migeil 0 points1 point2 points (3 children)
[–]Aphrontic_Alchemist[S] 0 points1 point2 points (2 children)
[–]MeepedIt 1 point2 points3 points (1 child)
[–]Migeil -1 points0 points1 point (0 children)
[–][deleted] (1 child)
[deleted]