From c4d343b3fd6f8ced73b5c98689f11d536ce48d56 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Sat, 30 Sep 2017 23:33:54 +0330 Subject: [PATCH] post(typoclassopedia): better formatting --- ...2017-09-27-typoclassopedia-exercise-answers.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/_posts/2017-09-27-typoclassopedia-exercise-answers.md b/_posts/2017-09-27-typoclassopedia-exercise-answers.md index 83885e9..934425b 100644 --- a/_posts/2017-09-27-typoclassopedia-exercise-answers.md +++ b/_posts/2017-09-27-typoclassopedia-exercise-answers.md @@ -322,12 +322,13 @@ pure f <*> x = pure (flip ($)) <*> x <*> pure f **Solution**: ```haskell -pure (flip ($)) <*> x <*> pure f = (pure (flip ($)) <*> x) <*> pure f -- <*> is left-associative -pure (flip ($)) <*> x <*> pure f = pure ($ f) <*> (pure (flip ($)) <*> x) -- interchange -pure (flip ($)) <*> x <*> pure f = pure (.) <*> pure ($ f) <*> pure (flip ($)) <*> x -- composition -pure (flip ($)) <*> x <*> pure f = pure (($ f) . (flip ($))) <*> x -- homomorphism -pure (flip ($)) <*> x <*> pure f = pure ((flip ($) f) . (flip ($))) <*> x -- identical -pure (flip ($)) <*> x <*> pure f = pure f <*> x +pure (flip ($)) <*> x <*> pure f + = (pure (flip ($)) <*> x) <*> pure f -- <*> is left-associative + = pure ($ f) <*> (pure (flip ($)) <*> x) -- interchange + = pure (.) <*> pure ($ f) <*> pure (flip ($)) <*> x -- composition + = pure (($ f) . (flip ($))) <*> x -- homomorphism + = pure ((flip ($) f) . (flip ($))) <*> x -- identical + = pure f <*> x ``` Explanation of the last transformation: @@ -344,3 +345,5 @@ You can check the type of `(flip ($) f) . (flip ($))` is something like this (de λ: :t (flip ($) f) . (flip ($)) (flip ($) f) . (flip ($)) :: Floating c => c -> c ``` + +Also see [this question on Stack Overflow](https://stackoverflow.com/questions/46503793/applicative-prove-pure-f-x-pure-flip-x-pure-f/46505868#46505868) which includes alternative proofs.