Created
January 3, 2014 02:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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