Skip to content

Instantly share code, notes, and snippets.

@pedrofurla
Created January 3, 2014 02:49
Show Gist options
  • Select an option

  • Save pedrofurla/8231743 to your computer and use it in GitHub Desktop.

Select an option

Save pedrofurla/8231743 to your computer and use it in GitHub Desktop.
Apply (State s) is confusing to the extreme ... my variable names doesn't help either
instance Apply (State s) where
-- Apply f ⇒ (<*>) :: f (a -> b) -> f a -> f b
-- Apply (State s) ⇒ (<*>) :: State s (a -> b) -> State s a -> State s b
--sab <*> sa = (\f → f <$> sa) <$> sab
sab <*> sa =
let
fsab = runState sab -- ∷ s → (a → b, s)
fsa = runState sa -- ∷ s → (a, s)
apply s =
let
as = fsa s
a = fst as
abs = fsab (snd as)
ab = fst abs
s2 = snd abs
in
(ab a, s2)
in
State { runState = apply }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment