Last active
May 18, 2017 01:12
-
-
Save jinjor/a78d5b3bf08079a50784ecdafe7fd049 to your computer and use it in GitHub Desktop.
type class exercise in Elm
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
| import Html exposing (text) | |
| main = | |
| text (toString <| allTheSame equal [ obj1, obj2, obj3 ]) | |
| obj1 = { id = 1, name = "foo" } | |
| obj2 = { id = 1, name = "bar" } | |
| obj3 = { id = 1, name = "baz" } | |
| equal a b = | |
| a.id == b.id | |
| type alias Eq a = a -> a -> Bool | |
| allTheSame : Eq a -> List a -> Bool | |
| allTheSame eq list = | |
| case list of | |
| x :: y :: rest -> | |
| eq x y && allTheSame eq (y :: rest) | |
| _ -> | |
| True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment