Created
October 6, 2014 03:23
-
-
Save FranklinChen/e6ba90b0e3ec90eb121a to your computer and use it in GitHub Desktop.
Example of point-free style
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
import Control.Category ((>>>)) | |
data Option = Option { name :: String } | |
-- Point-free style. Is this readable? | |
-- | |
-- An Option matches a String if: we get the name of the Option and then prepend "--" to it, test whether that is equal | |
-- to the given String. | |
matches :: Option -> String -> Bool | |
matches = name >>> ("--" ++) >>> (==) | |
-- Example | |
helpOption :: Option | |
helpOption = Option "help" | |
-- Example usage | |
example :: Bool | |
example = helpOption `matches` "--help" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment