Last active
January 2, 2016 19:29
-
-
Save msolli/7a980556a427e87e6477 to your computer and use it in GitHub Desktop.
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
{-| | |
Solutions in Elm for challenges 1, 2 and 3 from | |
http://bartoszmilewski.com/2014/11/04/category-the-essence-of-composition/ | |
-} | |
import Graphics.Element exposing (show) | |
{- id is called identity i elm-core -} | |
id : a -> a | |
id x = | |
x | |
{- Same as (>>) infix operator in elm-core -} | |
compose : (a -> b) -> (b -> c) -> a -> c | |
compose f g x = | |
g (f x) | |
addOne : number -> number | |
addOne x = | |
x + 1 | |
addOneWithId : number -> number | |
addOneWithId = | |
compose addOne id | |
idWithAddOne : number -> number | |
idWithAddOne = | |
compose id addOne | |
main = show [ addOneWithId 41 == addOne 41 | |
, idWithAddOne 41 == addOne 41 | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment