git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix Ord.
commit6a2a39e2d497e48c14b5b43c79d63b58a9d38541 authorPhil Freeman <paf31@cantab.net> dateMon 10 Mar 2014, 23:04 (13 years ago) parentbfd4078
3 files changed+44−33
examples/passing/Operators.purs+4 prelude/prelude.purs+39−32 tests/Main.hs+1−1
examples/passing/Operators.purs+4
@@ -54,6 +54,9 @@ module Operators2 where
5454
5555 test13 = \(<%>) a b -> a <%> b
5656
57+ test14 :: Number -> Number -> Boolean
58+ test14 a b = a < b
59+
5760module Main where
5861
5962import Operators1
@@ -79,4 +82,5 @@ main =
7982 , show test11
8083 , show (test12 k 1 2)
8184 , show (test13 k 1 2)
85+ , show (test14 1 2)
8286 ]
prelude/prelude.purs+39−32
@@ -172,46 +172,53 @@ module Prelude where
172172 (==) _ _ = false
173173 (/=) xs ys = not (xs == ys)
174174
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+
175185 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+
176192 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+
177199 infixl 4 <=
178− infixl 4 >=
179200
180− class Ord a where
181− (<) :: a -> a -> Boolean
182− (>) :: a -> a -> Boolean
183− (<=) :: a -> a -> Boolean
184− (>=) :: a -> a -> Boolean
185−
186− foreign import numLess "function numLess(n1) {\
187− \ return function(n2) {\
188− \ return n1 < n2;\
189− \ };\
190− \}" :: Number -> Number -> Boolean
201+ (<=) :: forall a. (Ord a) => a -> a -> Boolean
202+ (<=) a1 a2 = case a1 `compare` a2 of
203+ GT -> false
204+ _ -> true
205+
206+ infixl 4 >=
191207
192− foreign import numLessEq "function numLessEq(n1) {\
193− \ return function(n2) {\
194− \ return n1 <= n2;\
195− \ };\
196− \}" :: Number -> Number -> Boolean
208+ (>=) :: forall a. (Ord a) => a -> a -> Boolean
209+ (>=) a1 a2 = case a1 `compare` a2 of
210+ LT -> false
211+ _ -> true
197212
198− foreign import numGreater "function numGreater(n1) {\
199− \ return function(n2) {\
200− \ return n1 > n2;\
201− \ };\
202− \}" :: Number -> Number -> Boolean
203−
204− foreign import numGreaterEq "function numGreaterEq(n1) {\
205− \ return function(n2) {\
206− \ return n1 >= n2;\
207− \ };\
208− \}" :: Number -> Number -> Boolean
213+ foreign import numCompare
214+ "function numCompare(n1) {\
215+ \ return function(n2) {\
216+ \ return n1 < n2 ? module.LT : n1 > n2 ? module.GT : module.EQ;\
217+ \ };\
218+ \}" :: Number -> Number -> Ordering
209219
210220 instance ordNumber :: Ord Number where
211− (<) = numLess
212− (>) = numGreater
213− (<=) = numLessEq
214− (>=) = numGreaterEq
221+ compare = numCompare
215222
216223 infixl 10 &
217224 infixl 10 |
tests/Main.hs+1−1
@@ -63,7 +63,7 @@ assertCompiles :: FilePath -> IO ()
6363assertCompiles inputFile = do
6464 putStrLn $ "assert " ++ inputFile ++ " compiles successfully"
6565 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
6767 process <- findNodeProcess
6868 result <- traverse (\node -> readProcessWithExitCode node [] js) process
6969 case result of