git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Replace ++ with Semigroup in Prelude
d9a1d43Phil Freeman
examples/passing/Operators.purs+1−2
@@ -4,6 +4,7 @@ module Main where
4 import Control.Monad.Eff
4 import Control.Monad.Eff
5 import Debug.Trace
5 import Debug.Trace
6
6
7+ bar :: String -> String -> String
7 bar = \s1 s2 -> s1 ++ s2
8 bar = \s1 s2 -> s1 ++ s2
8
9
9 test1 :: forall n. (Num n) => n -> n -> (n -> n -> n) -> n
10 test1 :: forall n. (Num n) => n -> n -> (n -> n -> n) -> n
@@ -26,8 +27,6 @@ module Main where
26
27
27 test6 = ((\x -> x) `k` 2) 3
28 test6 = ((\x -> x) `k` 2) 3
28
29
29− (<>) = \s1 s2 -> s1 ++ s2
30−
31 test7 = "Hello" <> "World!"
30 test7 = "Hello" <> "World!"
32
31
33 (@@) :: forall a b. (a -> b) -> a -> b
32 (@@) :: forall a b. (a -> b) -> a -> b
prelude/prelude.purs+17−5
@@ -325,13 +325,25 @@ module Prelude where
325 (||) = boolOr
325 (||) = boolOr
326 not = boolNot
326 not = boolNot
327
327
328+ infixr 6 <>
329+
330+ class Semigroup s where
331+ (<>) :: s -> s -> s
332+
328 infixr 5 ++
333 infixr 5 ++
329
334
335+ (++) :: forall s. (Semigroup s) => s -> s -> s
336+ (++) = (<>)
337+
330− foreign import (++) "function $plus$plus(s1) {\
338+ foreign import concatString
339+ "function concatString(s1) {\
331− \ return function(s2) {\
340+ \ return function(s2) {\
332− \ return s1 + s2;\
341+ \ return s1 + s2;\
333− \ };\
342+ \ };\
334− \}" :: String -> String -> String
343+ \}" :: String -> String -> String
344+
345+ instance semigroupString :: Semigroup String where
346+ (<>) = concatString
335
347
336module Data.Eq where
348module Data.Eq where
337
349
src/Language/PureScript/Constants.hs+6
@@ -29,6 +29,9 @@ module Language.PureScript.Constants where
29(++) :: String
29(++) :: String
30(++) = "++"
30(++) = "++"
31
31
32+(<>) :: String
33+(<>) = "<>"
34+
32(>>=) :: String
35(>>=) :: String
33(>>=) = ">>="
36(>>=) = ">>="
34
37
@@ -146,6 +149,9 @@ pokeSTArray = "pokeSTArray"
146monadEffDictionary :: String
149monadEffDictionary :: String
147monadEffDictionary = "monadEff"
150monadEffDictionary = "monadEff"
148
151
152+semigroupString :: String
153+semigroupString = "semigroupString"
154+
149numNumber :: String
155numNumber :: String
150numNumber = "numNumber"
156numNumber = "numNumber"
151
157
src/Language/PureScript/Optimizer.hs−1
@@ -64,7 +64,6 @@ optimize opts | optionsNoOptimizations opts = id
64 , inlineOperator (C.$) $ \f x -> JSApp f [x]
64 , inlineOperator (C.$) $ \f x -> JSApp f [x]
65 , inlineOperator (C.#) $ \x f -> JSApp f [x]
65 , inlineOperator (C.#) $ \x f -> JSApp f [x]
66 , inlineOperator (C.!!) $ flip JSIndexer
66 , inlineOperator (C.!!) $ flip JSIndexer
67− , inlineOperator (C.++) $ JSBinary Add
68 , inlineCommonOperators ]
67 , inlineCommonOperators ]
69
68
70untilFixedPoint :: (Eq a) => (a -> a) -> a -> a
69untilFixedPoint :: (Eq a) => (a -> a) -> a -> a
src/Language/PureScript/Optimizer/Inliner.hs+4−1
@@ -83,7 +83,10 @@ inlineOperator op f = everywhere (mkT convert)
83
83
84inlineCommonOperators :: JS -> JS
84inlineCommonOperators :: JS -> JS
85inlineCommonOperators = applyAll
85inlineCommonOperators = applyAll
86+ [ binary C.semigroupString (C.++) Add
87+ , binary C.semigroupString (C.<>) Add
88+
86− [ binary C.numNumber (C.+) Add
89+ , binary C.numNumber (C.+) Add
87 , binary C.numNumber (C.-) Subtract
90 , binary C.numNumber (C.-) Subtract
88 , binary C.numNumber (C.*) Multiply
91 , binary C.numNumber (C.*) Multiply
89 , binary C.numNumber (C./) Divide
92 , binary C.numNumber (C./) Divide