Skip to content

Instantly share code, notes, and snippets.

@msolli
Last active January 2, 2016 19:29
Show Gist options
  • Save msolli/7a980556a427e87e6477 to your computer and use it in GitHub Desktop.
Save msolli/7a980556a427e87e6477 to your computer and use it in GitHub Desktop.
{-|
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