Last active
August 29, 2015 14:14
-
-
Save rknuu/c54dbc55228cb0b11ecb to your computer and use it in GitHub Desktop.
Why Haskell is cool
This file contains 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
-- Taken from https://www.youtube.com/watch?v=6KkF5-_erns#t=1154 | |
-- Original code taken from https://github.com/haskelllive/haskelllive/blob/episode-1/Chess.hs | |
module Chess where | |
-- This call reads in a string grid of a chessboard with each row separated by a newline | |
-- and returns an encoded board where each position could be Nothing or an encoded piece | |
-- type (returned from readSquare). | |
-- | |
readBoard :: String -> Maybe Board | |
readBoard = mapM readRows . lines | |
where readRows = mapM readSquare | |
-- This does the exact same thing, only using function composition to eliminate | |
-- unnecessary inner definitions. | |
readBoard = (mapM . mapM) readSquare . lines | |
-- Gotta love function compositions! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment