git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update Prelude
commit8f956e0ab5f491b8d0c943bbc217ce572d08257f authorPhil Freeman <paf31@cantab.net> dateSat 5 Apr 2014, 18:55 (13 years ago) parentd701c52
5 files changed+23−10
examples/passing/Operators.purs+2 prelude/prelude.purs+16−9 src/Language/PureScript/Constants.hs+3 src/Language/PureScript/Optimizer.hs−1 src/Language/PureScript/Optimizer/Inliner.hs+2
examples/passing/Operators.purs+2
@@ -3,6 +3,7 @@ module Main where
33 import Control.Monad.Eff
44 import Debug.Trace
55
6+ bar :: String -> String -> String
67 bar = \s1 s2 -> s1 ++ s2
78
89 test1 :: forall n. (Num n) => n -> n -> (n -> n -> n) -> n
@@ -25,6 +26,7 @@ module Main where
2526
2627 test6 = ((\x -> x) `k` 2) 3
2728
29+ (<>) :: String -> String -> String
2830 (<>) = \s1 s2 -> s1 ++ s2
2931
3032 test7 = "Hello" <> "World!"
prelude/prelude.purs+16−9
@@ -8,7 +8,7 @@ module Prelude where
88
99 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
1010 on f g x y = g x `f` g y
11−
11+
1212 asTypeOf :: forall a. a -> a -> a
1313 asTypeOf x _ = x
1414
@@ -59,7 +59,7 @@ module Prelude where
5959
6060 infixl 4 <*>
6161
62− class Applicative f where
62+ class (Functor f) <= Applicative f where
6363 pure :: forall a. a -> f a
6464 (<*>) :: forall a b. f (a -> b) -> f a -> f b
6565
@@ -74,7 +74,7 @@ module Prelude where
7474
7575 infixl 1 >>=
7676
77− class Monad m where
77+ class (Applicative m) <= Monad m where
7878 return :: forall a. a -> m a
7979 (>>=) :: forall a b. m a -> (a -> m b) -> m b
8080
@@ -192,7 +192,7 @@ module Prelude where
192192 show GT = "GT"
193193 show EQ = "EQ"
194194
195− class Ord a where
195+ class (Eq a) <= Ord a where
196196 compare :: a -> a -> Ordering
197197
198198 infixl 4 <
@@ -334,11 +334,18 @@ module Prelude where
334334
335335 infixr 5 ++
336336
337− foreign import (++) "function $plus$plus(s1) {\
338− \ return function(s2) {\
339− \ return s1 + s2;\
340− \ };\
341− \}" :: String -> String -> String
337+ class Semigroup a where
338+ (++) :: a -> a -> a
339+
340+ foreign import concatString
341+ "function concatString(s1) {\
342+ \ return function(s2) {\
343+ \ return s1 + s2;\
344+ \ };\
345+ \}" :: String -> String -> String
346+
347+ instance semigroupString :: Semigroup String where
348+ (++) = concatString
342349
343350module Data.Eq where
344351
src/Language/PureScript/Constants.hs+3
@@ -167,6 +167,9 @@ bitsNumber = "bitsNumber"
167167boolLikeBoolean :: String
168168boolLikeBoolean = "boolLikeBoolean"
169169
170+semigroupString :: String
171+semigroupString = "semigroupString"
172+
170173-- Main module
171174
172175main :: String
src/Language/PureScript/Optimizer.hs−1
@@ -66,7 +66,6 @@ optimize opts | optionsNoOptimizations opts = id
6666 , inlineOperator (C.$) $ \f x -> JSApp f [x]
6767 , inlineOperator (C.#) $ \x f -> JSApp f [x]
6868 , inlineOperator (C.!!) $ flip JSIndexer
69− , inlineOperator (C.++) $ JSBinary Add
7069 , inlineCommonOperators ])
7170
7271untilFixedPoint :: (Eq a) => (a -> a) -> a -> a
src/Language/PureScript/Optimizer/Inliner.hs+2
@@ -110,6 +110,8 @@ inlineCommonOperators = applyAll
110110 , binary C.eqBoolean (C.==) EqualTo
111111 , binary C.eqBoolean (C./=) NotEqualTo
112112
113+ , binary C.semigroupString (C.++) Add
114+
113115 , binaryFunction C.bitsNumber C.shl ShiftLeft
114116 , binaryFunction C.bitsNumber C.shr ShiftRight
115117 , binaryFunction C.bitsNumber C.zshr ZeroFillShiftRight