git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix Ord.
6a2a39ePhil Freeman
examples/passing/Operators.purs+4
@@ -54,6 +54,9 @@ module Operators2 where
54
54
55 test13 = \(<%>) a b -> a <%> b
55 test13 = \(<%>) a b -> a <%> b
56
56
57+ test14 :: Number -> Number -> Boolean
58+ test14 a b = a < b
59+
57module Main where
60module Main where
58
61
59import Operators1
62import Operators1
@@ -79,4 +82,5 @@ main =
79 , show test11
82 , show test11
80 , show (test12 k 1 2)
83 , show (test12 k 1 2)
81 , show (test13 k 1 2)
84 , show (test13 k 1 2)
85+ , show (test14 1 2)
82 ]
86 ]
prelude/prelude.purs+39−32
@@ -172,46 +172,53 @@ module Prelude where
172 (==) _ _ = false
172 (==) _ _ = false
173 (/=) xs ys = not (xs == ys)
173 (/=) xs ys = not (xs == ys)
174
174
175+ data Ordering = LT | GT | EQ
176+
177+ instance showOrdering :: Show Ordering where
178+ show LT = "LT"
179+ show GT = "GT"
180+ show EQ = "EQ"
181+
182+ class Ord a where
183+ compare :: a -> a -> Ordering
184+
175 infixl 4 <
185 infixl 4 <
186+
187+ (<) :: forall a. (Ord a) => a -> a -> Boolean
188+ (<) a1 a2 = case a1 `compare` a2 of
189+ LT -> true
190+ _ -> false
191+
176 infixl 4 >
192 infixl 4 >
193+
194+ (>) :: forall a. (Ord a) => a -> a -> Boolean
195+ (>) a1 a2 = case a1 `compare` a2 of
196+ GT -> true
197+ _ -> false
198+
177 infixl 4 <=
199 infixl 4 <=
178− infixl 4 >=
179
200
180− class Ord a where
181− (<) :: a -> a -> Boolean
201+ (<=) :: forall a. (Ord a) => a -> a -> Boolean
182− (>) :: a -> a -> Boolean
202+ (<=) a1 a2 = case a1 `compare` a2 of
183− (<=) :: a -> a -> Boolean
203+ GT -> false
184− (>=) :: a -> a -> Boolean
204+ _ -> true
185−
205+
186− foreign import numLess "function numLess(n1) {\
206+ infixl 4 >=
187− \ return function(n2) {\
188− \ return n1 < n2;\
189− \ };\
190− \}" :: Number -> Number -> Boolean
191
207
192− foreign import numLessEq "function numLessEq(n1) {\
208+ (>=) :: forall a. (Ord a) => a -> a -> Boolean
193− \ return function(n2) {\
209+ (>=) a1 a2 = case a1 `compare` a2 of
194− \ return n1 <= n2;\
210+ LT -> false
195− \ };\
211+ _ -> true
196− \}" :: Number -> Number -> Boolean
197
212
198− foreign import numGreater "function numGreater(n1) {\
213+ foreign import numCompare
214+ "function numCompare(n1) {\
199− \ return function(n2) {\
215+ \ return function(n2) {\
200− \ return n1 > n2;\
216+ \ return n1 < n2 ? module.LT : n1 > n2 ? module.GT : module.EQ;\
201− \ };\
202− \}" :: Number -> Number -> Boolean
203−
204− foreign import numGreaterEq "function numGreaterEq(n1) {\
205− \ return function(n2) {\
206− \ return n1 >= n2;\
207− \ };\
217+ \ };\
208− \}" :: Number -> Number -> Boolean
218+ \}" :: Number -> Number -> Ordering
209
219
210 instance ordNumber :: Ord Number where
220 instance ordNumber :: Ord Number where
211− (<) = numLess
221+ compare = numCompare
212− (>) = numGreater
213− (<=) = numLessEq
214− (>=) = numGreaterEq
215
222
216 infixl 10 &
223 infixl 10 &
217 infixl 10 |
224 infixl 10 |
tests/Main.hs+1−1
@@ -63,7 +63,7 @@ assertCompiles :: FilePath -> IO ()
63assertCompiles inputFile = do
63assertCompiles inputFile = do
64 putStrLn $ "assert " ++ inputFile ++ " compiles successfully"
64 putStrLn $ "assert " ++ inputFile ++ " compiles successfully"
65 prelude <- preludeFilename
65 prelude <- preludeFilename
66− assert (P.defaultOptions { P.optionsMain = Just "Main", P.optionsNoOptimizations = True, P.optionsModules = ["Main"] }) [prelude, inputFile] $ either (return . Just) $ \js -> do
66+ assert (P.defaultOptions { P.optionsMain = Just "Main", P.optionsModules = ["Main"] }) [prelude, inputFile] $ either (return . Just) $ \js -> do
67 process <- findNodeProcess
67 process <- findNodeProcess
68 result <- traverse (\node -> readProcessWithExitCode node [] js) process
68 result <- traverse (\node -> readProcessWithExitCode node [] js) process
69 case result of
69 case result of