Skip to content

Instantly share code, notes, and snippets.

@owickstrom
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save owickstrom/4d92faec8d38db95e800 to your computer and use it in GitHub Desktop.

Select an option

Save owickstrom/4d92faec8d38db95e800 to your computer and use it in GitHub Desktop.
Purescript Eq instance
module Main where
import Debug.Trace
data T = A | B Number
instance eqT :: Eq T where
A == A = true
(B v1) == (B v2) = v1 == v2
_ == _ = false
t1 /= t2 == not (t1 == t2)
main = print $ [A, B 123] == [A, B 123]
"Eq.purs" (line 6, column 3):
unexpected UName "A"
expecting no indentation or end of input
@fredyr
Copy link
Copy Markdown

fredyr commented Apr 18, 2015

Not exactly sure why, but this seem to work better

instance eqT :: Eq T where
  (==)A A = true
  (==) (B v1) (B v2) = v1 == v2
  (== )_ _ = false
  (/=) t1 t2 = not (t1 == t2)

@paf31
Copy link
Copy Markdown

paf31 commented Apr 18, 2015

Yes, the compiler doesn't support infix pattern matches right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment