Last active
August 29, 2015 14:10
-
-
Save kevinmeredith/5ee5c45657e2f46a56e2 to your computer and use it in GitHub Desktop.
Equational Reasoning in Haskell
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
| -- source of `tranpose`: `Applicative programming with effects` by McBride/Paterson | |
| transpose :: [[a]] -> [[a]] | |
| transpose [] = repeat [] | |
| transpose (xs : xss) = zipWith (:) xs (transpose xss) | |
| -- I didn't fully understand this function, so I decided to fully evaluate it by substituion. | |
| transpose [[1,2,3], [4,5,6]] === zipWith (:) [1,2,3] (transpose [[4,5,6]]) | |
| === zipWith (:) [1,2,3] (zipWith (:) [4,5,6] (transpose [])) | |
| === zipWith (:) [1,2,3] (zipWith (:) [4,5,6] (repeat [])) | |
| === zipWith (:) [1,2,3] ([[4], [5], [6]]) | |
| === [[1,4], [2,5], [3,6]] | |
| -- Let's confirm that the `transpose` function call equals the broken out (by substitution) expression | |
| ghci> transpose [[1,2,3],[4,5,6]] | |
| [[1,4],[2,5],[3,6]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment