Skip to content

Commit 291ff0b

Browse files
committed
Merge pull request purescript#1870 from purescript/eq-deriving
Eq and Ord deriving
2 parents c9a2235 + b4e5bf2 commit 291ff0b

File tree

3 files changed

+319
-138
lines changed

3 files changed

+319
-138
lines changed

examples/passing/Deriving.purs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Main where
2+
3+
import Prelude
4+
import Test.Assert
5+
6+
data V
7+
8+
derive instance eqV :: Eq V
9+
10+
derive instance ordV :: Ord V
11+
12+
data X = X Int | Y String
13+
14+
derive instance eqX :: Eq X
15+
16+
derive instance ordX :: Ord X
17+
18+
newtype Z = Z { left :: X, right :: X }
19+
20+
derive instance eqZ :: Eq Z
21+
22+
main = do
23+
assert $ X 0 == X 0
24+
assert $ X 0 /= X 1
25+
assert $ Y "Foo" == Y "Foo"
26+
assert $ Y "Foo" /= Y "Bar"
27+
assert $ X 0 < X 1
28+
assert $ X 0 < Y "Foo"
29+
assert $ Y "Bar" < Y "Baz"
30+
assert $ z == z where
31+
z = Z { left: X 0, right: Y "Foo" }

src/Language/PureScript/Constants.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ eq = "eq"
9898
notEq :: String
9999
notEq = "notEq"
100100

101+
compare :: String
102+
compare = "compare"
103+
101104
(&&) :: String
102105
(&&) = "&&"
103106

0 commit comments

Comments
 (0)