Skip to content

Instantly share code, notes, and snippets.

@jinjor
Last active May 18, 2017 01:12
Show Gist options
  • Select an option

  • Save jinjor/a78d5b3bf08079a50784ecdafe7fd049 to your computer and use it in GitHub Desktop.

Select an option

Save jinjor/a78d5b3bf08079a50784ecdafe7fd049 to your computer and use it in GitHub Desktop.
type class exercise in Elm
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