[Haskell-beginners] Applicative for State
mike h
mike_k_houghton at yahoo.co.uk
Mon Feb 6 19:40:12 UTC 2017
Hi,
I have a State by another name, Stat, just to experiment and learn.
newtype Stat s a = Stat { runStat :: s -> (a, s) }
instance Functor (Stat s) where
fmap f (Stat g) = Stat $ \s -> (f a, s) where
(a, s) = g s
instance Applicative (Stat s) where
pure a = Stat $ \s -> (a, s)
(Stat f) <*> (Stat g) = Stat $ \s -> (a, s) where
(a, s) = undefined
I really can’t get what the <*> in the Applicative should be!
I just do see how I ‘get the f out of the Stat’ and then apply it.
I’d be really grateful if someone would explain what it should be and the steps/reasoning needed to get there.
Many thanks
Mike
More information about the Beginners
mailing list