git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Install test support code automatically
commit54831daf280b37ef7f8ebbfce417fa6705cf7b21 authorHarry Garrood <harry@garrood.me> dateWed 29 Jul 2015, 17:01 (11 years ago) parentee3035f
18 files changed+27−1791
.gitignore+1 CONTRIBUTING.md+2−2 tests/Main.hs+24−15 tests/support/flattened/Control-Monad-Eff-Class.purs−24 tests/support/flattened/Control-Monad-Eff-Console.js−18 tests/support/flattened/Control-Monad-Eff-Console.purs−18 tests/support/flattened/Control-Monad-Eff-Unsafe.js−8 tests/support/flattened/Control-Monad-Eff-Unsafe.purs−10 tests/support/flattened/Control-Monad-Eff.js−62 tests/support/flattened/Control-Monad-Eff.purs−67 tests/support/flattened/Control-Monad-ST.js−38 tests/support/flattened/Control-Monad-ST.purs−42 tests/support/flattened/Data-Function.js−233 tests/support/flattened/Data-Function.purs−113 tests/support/flattened/Prelude.js−222 tests/support/flattened/Prelude.purs−860 tests/support/flattened/Test-Assert.js−27 tests/support/flattened/Test-Assert.purs−32
.gitignore+1
@@ -13,3 +13,4 @@ cabal.sandbox.config
1313bower_components/
1414tmp/
1515.stack-work/
16+tests/support/flattened/
CONTRIBUTING.md+2−2
@@ -9,8 +9,8 @@ Please follow the following guidelines:
99- Add at least a test to `examples/passing/` and possibly to `examples/failing`.
1010- Build the binaries and libs with `cabal build`
1111- Install the binaries and libs with `cabal install`.
12−- Run `cabal configure --enable-tests && cabal build && cabal test` to build the test suite.
13−- Build the core libraries by running the script in `core-tests`
12+- Run `cabal configure --enable-tests && cabal build && cabal test` to build the test suite. You will need `npm`, `node`, and `bower` on your PATH to run the tests.
13+- Build the core libraries by running the script in `core-tests`.
1414
1515If you would like to contribute, please consider the issues in the current milestone first. If you are a new contributor, you may want to have a go at the ["easy" issues](https://github.com/purescript/purescript/labels/easy) to get started.
1616
tests/Main.hs+24−15
@@ -13,7 +13,7 @@
1313-----------------------------------------------------------------------------
1414
1515{-# LANGUAGE DataKinds #-}
16−{-# LANGUAGE DoAndIfThenElse #-}
16+{-# LANGUAGE DoAndIfThenElse #-}
1717{-# LANGUAGE TupleSections #-}
1818{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1919{-# LANGUAGE FlexibleInstances #-}
@@ -61,23 +61,23 @@ makeActions :: M.Map P.ModuleName (FilePath, P.ForeignJS) -> P.MakeActions Test
6161makeActions foreigns = P.MakeActions getInputTimestamp getOutputTimestamp readExterns codegen progress
6262 where
6363 getInputTimestamp :: P.ModuleName -> Test (Either P.RebuildPolicy (Maybe UTCTime))
64− getInputTimestamp mn
64+ getInputTimestamp mn
6565 | isSupportModule (P.runModuleName mn) = return (Left P.RebuildNever)
6666 | otherwise = return (Left P.RebuildAlways)
6767 where
6868 isSupportModule = flip elem supportModules
69−
69+
7070 getOutputTimestamp :: P.ModuleName -> Test (Maybe UTCTime)
7171 getOutputTimestamp mn = do
7272 let filePath = modulesDir </> P.runModuleName mn
7373 exists <- liftIO $ doesDirectoryExist filePath
7474 return (if exists then Just (error "getOutputTimestamp: read timestamp") else Nothing)
75−
75+
7676 readExterns :: P.ModuleName -> Test (FilePath, String)
7777 readExterns mn = do
7878 let filePath = modulesDir </> P.runModuleName mn </> "externs.purs"
7979 (filePath, ) <$> readTextFile filePath
80−
80+
8181 codegen :: CF.Module CF.Ann -> P.Environment -> P.SupplyVar -> P.Externs -> Test ()
8282 codegen m _ nextVar exts = do
8383 let mn = CF.moduleName m
@@ -94,15 +94,15 @@ makeActions foreigns = P.MakeActions getInputTimestamp getOutputTimestamp readEx
9494 writeTextFile jsFile pjs
9595 maybe (return ()) (writeTextFile foreignFile . snd) $ CF.moduleName m `M.lookup` foreigns
9696 writeTextFile externsFile exts
97−
97+
9898 readTextFile :: FilePath -> Test String
9999 readTextFile path = liftIO $ readFile path
100−
100+
101101 writeTextFile :: FilePath -> String -> Test ()
102102 writeTextFile path text = liftIO $ do
103103 createDirectoryIfMissing True (takeDirectory path)
104104 writeFile path text
105−
105+
106106 progress :: String -> Test ()
107107 progress = liftIO . putStrLn
108108
@@ -117,9 +117,9 @@ compile inputFiles foreigns = runTest $ do
117117 ms <- P.parseModulesFromFiles id fs
118118 P.make (makeActions foreigns) (map (\(k, v) -> (Right k, v)) ms)
119119
120−assert :: [FilePath] ->
121− M.Map P.ModuleName (FilePath, P.ForeignJS) ->
122− (Either P.MultipleErrors P.Environment -> IO (Maybe String)) ->
120+assert :: [FilePath] ->
121+ M.Map P.ModuleName (FilePath, P.ForeignJS) ->
122+ (Either P.MultipleErrors P.Environment -> IO (Maybe String)) ->
123123 IO ()
124124assert inputFiles foreigns f = do
125125 e <- compile inputFiles foreigns
@@ -132,7 +132,7 @@ assertCompiles :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> IO
132132assertCompiles inputFiles foreigns = do
133133 putStrLn $ "Assert " ++ last inputFiles ++ " compiles successfully"
134134 assert inputFiles foreigns $ \e ->
135− case e of
135+ case e of
136136 Left errs -> return . Just . P.prettyPrintMultipleErrors False $ errs
137137 Right _ -> do
138138 process <- findNodeProcess
@@ -154,13 +154,14 @@ assertDoesNotCompile inputFiles foreigns = do
154154
155155findNodeProcess :: IO (Maybe String)
156156findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
157− where
157+ where
158158 names = ["nodejs", "node"]
159159
160160main :: IO ()
161161main = do
162+ fetchSupportCode
162163 cwd <- getCurrentDirectory
163−
164+
164165 let supportDir = cwd </> "tests" </> "support" </> "flattened"
165166 let supportFiles ext = Glob.globDir1 (Glob.compile ("*." ++ ext)) supportDir
166167
@@ -169,7 +170,7 @@ main = do
169170
170171 foreignFiles <- forM supportJS (\f -> (f,) <$> readFile f)
171172 Right (foreigns, _) <- runExceptT $ runWriterT $ P.parseForeignModulesFromFiles foreignFiles
172−
173+
173174 let passing = cwd </> "examples" </> "passing"
174175 passingTestCases <- getDirectoryContents passing
175176 forM_ passingTestCases $ \inputFile -> when (".purs" `isSuffixOf` inputFile) $
@@ -180,6 +181,14 @@ main = do
180181 assertDoesNotCompile (supportPurs ++ [failing </> inputFile]) foreigns
181182 exitSuccess
182183
184+fetchSupportCode :: IO ()
185+fetchSupportCode = do
186+ setCurrentDirectory "tests/support"
187+ callProcess "npm" ["install"]
188+ callProcess "bower" ["install"]
189+ callProcess "node" ["setup.js"]
190+ setCurrentDirectory "../.."
191+
183192supportModules :: [String]
184193supportModules =
185194 [ "Control.Monad.Eff.Class"
tests/support/flattened/Control-Monad-Eff-Class.pursdeleted−24
@@ -1,24 +0,0 @@
1−module Control.Monad.Eff.Class
2− ( MonadEff
3− , liftEff
4− ) where
5−
6−import Prelude
7−
8−import Control.Monad.Eff
9−
10−-- | The `MonadEff` class captures those monads which support native effects.
11−-- |
12−-- | Instances are provided for `Eff` itself, and the standard monad transformers.
13−-- |
14−-- | `liftEff` can be used in any appropriate monad transformer stack to lift an action
15−-- | of type `Eff eff a` into the monad.
16−-- |
17−-- | Note that `MonadEff` is parameterized by the row of effects, so type inference can be
18−-- | tricky. It is generally recommended to either work with a polymorphic row of effects,
19−-- | or a concrete, closed row of effects such as `(trace :: Trace)`.
20−class (Monad m) <= MonadEff eff m where
21− liftEff :: forall a. Eff eff a -> m a
22−
23−instance monadEffEff :: MonadEff eff (Eff eff) where
24− liftEff = id
tests/support/flattened/Control-Monad-Eff-Console.jsdeleted−18
@@ -1,18 +0,0 @@
1−/* global exports, console */
2−"use strict";
3−
4−// module Control.Monad.Eff.Console
5−
6−exports.log = function (s) {
7− return function () {
8− console.log(s);
9− return {};
10− };
11−};
12−
13−exports.error = function (s) {
14− return function () {
15− console.error(s);
16− return {};
17− };
18−};
tests/support/flattened/Control-Monad-Eff-Console.pursdeleted−18
@@ -1,18 +0,0 @@
1−module Control.Monad.Eff.Console where
2−
3−import Prelude
4−
5−import Control.Monad.Eff
6−
7−-- | The `CONSOLE` effect represents those computations which write to the console.
8−foreign import data CONSOLE :: !
9−
10−-- | Write a message to the console.
11−foreign import log :: forall eff. String -> Eff (console :: CONSOLE | eff) Unit
12−
13−-- | Write an error to the console.
14−foreign import error :: forall eff. String -> Eff (console :: CONSOLE | eff) Unit
15−
16−-- | Write a value to the console, using its `Show` instance to produce a `String`.
17−print :: forall a eff. (Show a) => a -> Eff (console :: CONSOLE | eff) Unit
18−print = log <<< show
tests/support/flattened/Control-Monad-Eff-Unsafe.jsdeleted−8
@@ -1,8 +0,0 @@
1−/* global exports */
2−"use strict";
3−
4−// module Control.Monad.Eff.Unsafe
5−
6−exports.unsafeInterleaveEff = function (f) {
7− return f;
8−};
tests/support/flattened/Control-Monad-Eff-Unsafe.pursdeleted−10
@@ -1,10 +0,0 @@
1−module Control.Monad.Eff.Unsafe where
2−
3−import Prelude
4−
5−import Control.Monad.Eff
6−
7−-- | Change the type of an effectful computation, allowing it to be run in another context.
8−-- |
9−-- | Note: use of this function can result in arbitrary side-effects.
10−foreign import unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
tests/support/flattened/Control-Monad-Eff.jsdeleted−62
@@ -1,62 +0,0 @@
1−/* global exports */
2−"use strict";
3−
4−// module Control.Monad.Eff
5−
6−exports.returnE = function (a) {
7− return function () {
8− return a;
9− };
10−};
11−
12−exports.bindE = function (a) {
13− return function (f) {
14− return function () {
15− return f(a())();
16− };
17− };
18−};
19−
20−exports.runPure = function (f) {
21− return f();
22−};
23−
24−exports.untilE = function (f) {
25− return function () {
26− while (!f());
27− return {};
28− };
29−};
30−
31−exports.whileE = function (f) {
32− return function (a) {
33− return function () {
34− while (f()) {
35− a();
36− }
37− return {};
38− };
39− };
40−};
41−
42−exports.forE = function (lo) {
43− return function (hi) {
44− return function (f) {
45− return function () {
46− for (var i = lo; i < hi; i++) {
47− f(i)();
48− }
49− };
50− };
51− };
52−};
53−
54−exports.foreachE = function (as) {
55− return function (f) {
56− return function () {
57− for (var i = 0, l = as.length; i < l; i++) {
58− f(as[i])();
59− }
60− };
61− };
62−};
tests/support/flattened/Control-Monad-Eff.pursdeleted−67
@@ -1,67 +0,0 @@
1−module Control.Monad.Eff
2− ( Eff()
3− , Pure()
4− , runPure
5− , untilE, whileE, forE, foreachE
6− ) where
7−
8−import Prelude
9−
10−-- | The `Eff` type constructor is used to represent _native_ effects.
11−-- |
12−-- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
13−-- |
14−-- | The first type parameter is a row of effects which represents the contexts in which a computation can be run, and the second type parameter is the return type.
15−foreign import data Eff :: # ! -> * -> *
16−
17−foreign import returnE :: forall e a. a -> Eff e a
18−
19−foreign import bindE :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
20−
21−-- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
22−-- |
23−-- | The `runPure` function can be used to run pure computations and obtain their result.
24−type Pure a = forall e. Eff e a
25−
26−-- | Run a pure computation and return its result.
27−-- |
28−-- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
29−-- | is to use parentheses instead.
30−foreign import runPure :: forall a. Pure a -> a
31−
32−instance functorEff :: Functor (Eff e) where
33− map = liftA1
34−
35−instance applyEff :: Apply (Eff e) where
36− apply = ap
37−
38−instance applicativeEff :: Applicative (Eff e) where
39− pure = returnE
40−
41−instance bindEff :: Bind (Eff e) where
42− bind = bindE
43−
44−instance monadEff :: Monad (Eff e)
45−
46−-- | Loop until a condition becomes `true`.
47−-- |
48−-- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
49−-- | until its return value is `true`.
50−foreign import untilE :: forall e. Eff e Boolean -> Eff e Unit
51−
52−-- | Loop while a condition is `true`.
53−-- |
54−-- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
55−-- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
56−foreign import whileE :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
57−
58−-- | Loop over a consecutive collection of numbers.
59−-- |
60−-- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
61−-- | between `lo` (inclusive) and `hi` (exclusive).
62−foreign import forE :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
63−
64−-- | Loop over an array of values.
65−-- |
66−-- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
67−foreign import foreachE :: forall e a. Array a -> (a -> Eff e Unit) -> Eff e Unit
tests/support/flattened/Control-Monad-ST.jsdeleted−38
@@ -1,38 +0,0 @@
1−/* global exports */
2−"use strict";
3−
4−// module Control.Monad.ST
5−
6−exports.newSTRef = function (val) {
7− return function () {
8− return { value: val };
9− };
10−};
11−
12−exports.readSTRef = function (ref) {
13− return function () {
14− return ref.value;
15− };
16−};
17−
18−exports.modifySTRef = function (ref) {
19− return function (f) {
20− return function () {
21− /* jshint boss: true */
22− return ref.value = f(ref.value);
23− };
24− };
25−};
26−
27−exports.writeSTRef = function (ref) {
28− return function (a) {
29− return function () {
30− /* jshint boss: true */
31− return ref.value = a;
32− };
33− };
34−};
35−
36−exports.runST = function (f) {
37− return f;
38−};
tests/support/flattened/Control-Monad-ST.pursdeleted−42
@@ -1,42 +0,0 @@
1−module Control.Monad.ST where
2−
3−import Prelude
4−
5−import Control.Monad.Eff (Eff(), runPure)
6−
7−-- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
8−-- |
9−-- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
10−-- |
11−-- | The `runST` function can be used to handle the `ST` effect.
12−foreign import data ST :: * -> !
13−
14−-- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
15−foreign import data STRef :: * -> * -> *
16−
17−-- | Create a new mutable reference.
18−foreign import newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
19−
20−-- | Read the current value of a mutable reference.
21−foreign import readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
22−
23−-- | Modify the value of a mutable reference by applying a function to the current value.
24−foreign import modifySTRef :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
25−
26−-- | Set the value of a mutable reference.
27−foreign import writeSTRef :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
28−
29−-- | Run an `ST` computation.
30−-- |
31−-- | Note: the type of `runST` uses a rank-2 type to constrain the phantom type `s`, such that the computation must not leak any mutable references
32−-- | to the surrounding computation.
33−-- |
34−-- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
35−foreign import runST :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
36−
37−-- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
38−-- |
39−-- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
40−-- | is to use parentheses instead.
41−pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
42−pureST st = runPure (runST st)
tests/support/flattened/Data-Function.jsdeleted−233
@@ -1,233 +0,0 @@
1−/* global exports */
2−"use strict";
3−
4−// module Data.Function
5−
6−exports.mkFn0 = function (fn) {
7− return function () {
8− return fn({});
9− };
10−};
11−
12−exports.mkFn1 = function (fn) {
13− return function (a) {
14− return fn(a);
15− };
16−};
17−
18−exports.mkFn2 = function (fn) {
19− /* jshint maxparams: 2 */
20− return function (a, b) {
21− return fn(a)(b);
22− };
23−};
24−
25−exports.mkFn3 = function (fn) {
26− /* jshint maxparams: 3 */
27− return function (a, b, c) {
28− return fn(a)(b)(c);
29− };
30−};
31−
32−exports.mkFn4 = function (fn) {
33− /* jshint maxparams: 4 */
34− return function (a, b, c, d) {
35− return fn(a)(b)(c)(d);
36− };
37−};
38−
39−exports.mkFn5 = function (fn) {
40− /* jshint maxparams: 5 */
41− return function (a, b, c, d, e) {
42− return fn(a)(b)(c)(d)(e);
43− };
44−};
45−
46−exports.mkFn6 = function (fn) {
47− /* jshint maxparams: 6 */
48− return function (a, b, c, d, e, f) {
49− return fn(a)(b)(c)(d)(e)(f);
50− };
51−};
52−
53−exports.mkFn7 = function (fn) {
54− /* jshint maxparams: 7 */
55− return function (a, b, c, d, e, f, g) {
56− return fn(a)(b)(c)(d)(e)(f)(g);
57− };
58−};
59−
60−exports.mkFn8 = function (fn) {
61− /* jshint maxparams: 8 */
62− return function (a, b, c, d, e, f, g, h) {
63− return fn(a)(b)(c)(d)(e)(f)(g)(h);
64− };
65−};
66−
67−exports.mkFn9 = function (fn) {
68− /* jshint maxparams: 9 */
69− return function (a, b, c, d, e, f, g, h, i) {
70− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);
71− };
72−};
73−
74−exports.mkFn10 = function (fn) {
75− /* jshint maxparams: 10 */
76− return function (a, b, c, d, e, f, g, h, i, j) {
77− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
78− };
79−};
80−
81−exports.runFn0 = function (fn) {
82− return fn();
83−};
84−
85−exports.runFn1 = function (fn) {
86− return function (a) {
87− return fn(a);
88− };
89−};
90−
91−exports.runFn2 = function (fn) {
92− return function (a) {
93− return function (b) {
94− return fn(a, b);
95− };
96− };
97−};
98−
99−exports.runFn3 = function (fn) {
100− return function (a) {
101− return function (b) {
102− return function (c) {
103− return fn(a, b, c);
104− };
105− };
106− };
107−};
108−
109−exports.runFn4 = function (fn) {
110− return function (a) {
111− return function (b) {
112− return function (c) {
113− return function (d) {
114− return fn(a, b, c, d);
115− };
116− };
117− };
118− };
119−};
120−
121−exports.runFn5 = function (fn) {
122− return function (a) {
123− return function (b) {
124− return function (c) {
125− return function (d) {
126− return function (e) {
127− return fn(a, b, c, d, e);
128− };
129− };
130− };
131− };
132− };
133−};
134−
135−exports.runFn6 = function (fn) {
136− return function (a) {
137− return function (b) {
138− return function (c) {
139− return function (d) {
140− return function (e) {
141− return function (f) {
142− return fn(a, b, c, d, e, f);
143− };
144− };
145− };
146− };
147− };
148− };
149−};
150−
151−exports.runFn7 = function (fn) {
152− return function (a) {
153− return function (b) {
154− return function (c) {
155− return function (d) {
156− return function (e) {
157− return function (f) {
158− return function (g) {
159− return fn(a, b, c, d, e, f, g);
160− };
161− };
162− };
163− };
164− };
165− };
166− };
167−};
168−
169−exports.runFn8 = function (fn) {
170− return function (a) {
171− return function (b) {
172− return function (c) {
173− return function (d) {
174− return function (e) {
175− return function (f) {
176− return function (g) {
177− return function (h) {
178− return fn(a, b, c, d, e, f, g, h);
179− };
180− };
181− };
182− };
183− };
184− };
185− };
186− };
187−};
188−
189−exports.runFn9 = function (fn) {
190− return function (a) {
191− return function (b) {
192− return function (c) {
193− return function (d) {
194− return function (e) {
195− return function (f) {
196− return function (g) {
197− return function (h) {
198− return function (i) {
199− return fn(a, b, c, d, e, f, g, h, i);
200− };
201− };
202− };
203− };
204− };
205− };
206− };
207− };
208− };
209−};
210−
211−exports.runFn10 = function (fn) {
212− return function (a) {
213− return function (b) {
214− return function (c) {
215− return function (d) {
216− return function (e) {
217− return function (f) {
218− return function (g) {
219− return function (h) {
220− return function (i) {
221− return function (j) {
222− return fn(a, b, c, d, e, f, g, h, i, j);
223− };
224− };
225− };
226− };
227− };
228− };
229− };
230− };
231− };
232− };
233−};
tests/support/flattened/Data-Function.pursdeleted−113
@@ -1,113 +0,0 @@
1−module Data.Function where
2−
3−import Prelude
4−
5−-- | The `on` function is used to change the domain of a binary operator.
6−-- |
7−-- | For example, we can create a function which compares two records based on the values of their `x` properties:
8−-- |
9−-- | ```purescript
10−-- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
11−-- | compareX = compare `on` _.x
12−-- | ```
13−on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
14−on f g x y = g x `f` g y
15−
16−-- | A function of zero arguments
17−foreign import data Fn0 :: * -> *
18−
19−-- | A function of one argument
20−foreign import data Fn1 :: * -> * -> *
21−
22−-- | A function of two arguments
23−foreign import data Fn2 :: * -> * -> * -> *
24−
25−-- | A function of three arguments
26−foreign import data Fn3 :: * -> * -> * -> * -> *
27−
28−-- | A function of four arguments
29−foreign import data Fn4 :: * -> * -> * -> * -> * -> *
30−
31−-- | A function of five arguments
32−foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
33−
34−-- | A function of six arguments
35−foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
36−
37−-- | A function of seven arguments
38−foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
39−
40−-- | A function of eight arguments
41−foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
42−
43−-- | A function of nine arguments
44−foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
45−
46−-- | A function of ten arguments
47−foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
48−
49−-- | Create a function of no arguments
50−foreign import mkFn0 :: forall a. (Unit -> a) -> Fn0 a
51−
52−-- | Create a function of one argument
53−foreign import mkFn1 :: forall a b. (a -> b) -> Fn1 a b
54−
55−-- | Create a function of two arguments from a curried function
56−foreign import mkFn2 :: forall a b c. (a -> b -> c) -> Fn2 a b c
57−
58−-- | Create a function of three arguments from a curried function
59−foreign import mkFn3 :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
60−
61−-- | Create a function of four arguments from a curried function
62−foreign import mkFn4 :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
63−
64−-- | Create a function of five arguments from a curried function
65−foreign import mkFn5 :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
66−
67−-- | Create a function of six arguments from a curried function
68−foreign import mkFn6 :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
69−
70−-- | Create a function of seven arguments from a curried function
71−foreign import mkFn7 :: forall a b c d e f g h. (a -> b -> c -> d -> e -> f -> g -> h) -> Fn7 a b c d e f g h
72−
73−-- | Create a function of eight arguments from a curried function
74−foreign import mkFn8 :: forall a b c d e f g h i. (a -> b -> c -> d -> e -> f -> g -> h -> i) -> Fn8 a b c d e f g h i
75−
76−-- | Create a function of nine arguments from a curried function
77−foreign import mkFn9 :: forall a b c d e f g h i j. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j) -> Fn9 a b c d e f g h i j
78−
79−-- | Create a function of ten arguments from a curried function
80−foreign import mkFn10 :: forall a b c d e f g h i j k. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k) -> Fn10 a b c d e f g h i j k
81−
82−-- | Apply a function of no arguments
83−foreign import runFn0 :: forall a. Fn0 a -> a
84−
85−-- | Apply a function of one argument
86−foreign import runFn1 :: forall a b. Fn1 a b -> a -> b
87−
88−-- | Apply a function of two arguments
89−foreign import runFn2 :: forall a b c. Fn2 a b c -> a -> b -> c
90−
91−-- | Apply a function of three arguments
92−foreign import runFn3 :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
93−
94−-- | Apply a function of four arguments
95−foreign import runFn4 :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
96−
97−-- | Apply a function of five arguments
98−foreign import runFn5 :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
99−
100−-- | Apply a function of six arguments
101−foreign import runFn6 :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
102−
103−-- | Apply a function of seven arguments
104−foreign import runFn7 :: forall a b c d e f g h. Fn7 a b c d e f g h -> a -> b -> c -> d -> e -> f -> g -> h
105−
106−-- | Apply a function of eight arguments
107−foreign import runFn8 :: forall a b c d e f g h i. Fn8 a b c d e f g h i -> a -> b -> c -> d -> e -> f -> g -> h -> i
108−
109−-- | Apply a function of nine arguments
110−foreign import runFn9 :: forall a b c d e f g h i j. Fn9 a b c d e f g h i j -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j
111−
112−-- | Apply a function of ten arguments
113−foreign import runFn10 :: forall a b c d e f g h i j k. Fn10 a b c d e f g h i j k -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k
tests/support/flattened/Prelude.jsdeleted−222
@@ -1,222 +0,0 @@
1−/* global exports */
2−"use strict";
3−
4−// module Prelude
5−
6−//- Functor --------------------------------------------------------------------
7−
8−exports.arrayMap = function (f) {
9− return function (arr) {
10− var l = arr.length;
11− var result = new Array(l);
12− for (var i = 0; i < l; i++) {
13− result[i] = f(arr[i]);
14− }
15− return result;
16− };
17−};
18−
19−//- Bind -----------------------------------------------------------------------
20−
21−exports.arrayBind = function (arr) {
22− return function (f) {
23− var result = [];
24− for (var i = 0, l = arr.length; i < l; i++) {
25− Array.prototype.push.apply(result, f(arr[i]));
26− }
27− return result;
28− };
29−};
30−
31−//- Monoid ---------------------------------------------------------------------
32−
33−exports.concatString = function (s1) {
34− return function (s2) {
35− return s1 + s2;
36− };
37−};
38−
39−exports.concatArray = function (xs) {
40− return function (ys) {
41− return xs.concat(ys);
42− };
43−};
44−
45−//- Semiring -------------------------------------------------------------------
46−
47−exports.intAdd = function (x) {
48− return function (y) {
49− /* jshint bitwise: false */
50− return x + y | 0;
51− };
52−};
53−
54−exports.intMul = function (x) {
55− return function (y) {
56− /* jshint bitwise: false */
57− return x * y | 0;
58− };
59−};
60−
61−exports.numAdd = function (n1) {
62− return function (n2) {
63− return n1 + n2;
64− };
65−};
66−
67−exports.numMul = function (n1) {
68− return function (n2) {
69− return n1 * n2;
70− };
71−};
72−
73−//- ModuloSemiring -------------------------------------------------------------
74−
75−exports.intDiv = function (x) {
76− return function (y) {
77− /* jshint bitwise: false */
78− return x / y | 0;
79− };
80−};
81−
82−exports.intMod = function (x) {
83− return function (y) {
84− return x % y;
85− };
86−};
87−
88−exports.numDiv = function (n1) {
89− return function (n2) {
90− return n1 / n2;
91− };
92−};
93−
94−//- Ring -----------------------------------------------------------------------
95−
96−exports.intSub = function (x) {
97− return function (y) {
98− /* jshint bitwise: false */
99− return x - y | 0;
100− };
101−};
102−
103−exports.numSub = function (n1) {
104− return function (n2) {
105− return n1 - n2;
106− };
107−};
108−
109−//- Eq -------------------------------------------------------------------------
110−
111−exports.refEq = function (r1) {
112− return function (r2) {
113− return r1 === r2;
114− };
115−};
116−
117−exports.refIneq = function (r1) {
118− return function (r2) {
119− return r1 !== r2;
120− };
121−};
122−
123−exports.eqArrayImpl = function (f) {
124− return function (xs) {
125− return function (ys) {
126− if (xs.length !== ys.length) return false;
127− for (var i = 0; i < xs.length; i++) {
128− if (!f(xs[i])(ys[i])) return false;
129− }
130− return true;
131− };
132− };
133−};
134−
135−exports.ordArrayImpl = function (f) {
136− return function (xs) {
137− return function (ys) {
138− var i = 0;
139− var xlen = xs.length;
140− var ylen = ys.length;
141− while (i < xlen && i < ylen) {
142− var x = xs[i];
143− var y = ys[i];
144− var o = f(x)(y);
145− if (o !== 0) {
146− return o;
147− }
148− i++;
149− }
150− if (xlen === ylen) {
151− return 0;
152− } else if (xlen > ylen) {
153− return -1;
154− } else {
155− return 1;
156− }
157− };
158− };
159−};
160−
161−//- Ord ------------------------------------------------------------------------
162−
163−exports.unsafeCompareImpl = function (lt) {
164− return function (eq) {
165− return function (gt) {
166− return function (x) {
167− return function (y) {
168− return x < y ? lt : x > y ? gt : eq;
169− };
170− };
171− };
172− };
173−};
174−
175−//- Lattice --------------------------------------------------------------------
176−
177−exports.boolOr = function (b1) {
178− return function (b2) {
179− return b1 || b2;
180− };
181−};
182−
183−exports.boolAnd = function (b1) {
184− return function (b2) {
185− return b1 && b2;
186− };
187−};
188−
189−//- ComplementedLattice --------------------------------------------------------
190−
191−exports.boolNot = function (b) {
192− return !b;
193−};
194−
195−//- Show -----------------------------------------------------------------------
196−
197−exports.showIntImpl = function (n) {
198− return n.toString();
199−};
200−
201−exports.showNumberImpl = function (n) {
202− /* jshint bitwise: false */
203− return n === (n | 0) ? n + ".0" : n.toString();
204−};
205−
206−exports.showCharImpl = function (c) {
207− return c === "'" ? "'\\''" : "'" + c + "'";
208−};
209−
210−exports.showStringImpl = function (s) {
211− return JSON.stringify(s);
212−};
213−
214−exports.showArrayImpl = function (f) {
215− return function (xs) {
216− var ss = [];
217− for (var i = 0, l = xs.length; i < l; i++) {
218− ss[i] = f(xs[i]);
219− }
220− return "[" + ss.join(",") + "]";
221− };
222−};
tests/support/flattened/Prelude.pursdeleted−860
@@ -1,860 +0,0 @@
1−module Prelude
2− ( Unit(), unit
3− , ($), (#)
4− , flip
5− , const
6− , asTypeOf
7− , otherwise
8− , Semigroupoid, compose, (<<<), (>>>)
9− , Category, id
10− , Functor, map, (<$>), (<#>), void
11− , Apply, apply, (<*>)
12− , Applicative, pure, liftA1
13− , Bind, bind, (>>=)
14− , Monad, return, liftM1, ap
15− , Semigroup, append, (<>), (++)
16− , Semiring, add, zero, mul, one, (+), (*)
17− , ModuloSemiring, div, mod, (/)
18− , Ring, sub, negate, (-)
19− , Num
20− , DivisionRing
21− , Eq, eq, (==), (/=)
22− , Ordering(..), Ord, compare, (<), (>), (<=), (>=)
23− , unsafeCompare
24− , Bounded, top, bottom
25− , BoundedOrd
26− , BooleanAlgebra, conj, disj, not, (&&), (||)
27− , Show, show
28− ) where
29−
30−-- | The `Unit` type has a single inhabitant, called `unit`. It represents
31−-- | values with no computational content.
32−-- |
33−-- | `Unit` is often used, wrapped in a monadic type constructor, as the
34−-- | return type of a computation where only
35−-- | the _effects_ are important.
36−newtype Unit = Unit {}
37−
38−-- | `unit` is the sole inhabitant of the `Unit` type.
39−unit :: Unit
40−unit = Unit {}
41−
42−infixr 0 $
43−infixl 1 #
44−
45−-- | Applies a function to its argument.
46−-- |
47−-- | ```purescript
48−-- | length $ groupBy productCategory $ filter isInStock $ products
49−-- | ```
50−-- |
51−-- | is equivalent to:
52−-- |
53−-- | ```purescript
54−-- | length (groupBy productCategory (filter isInStock products))
55−-- | ```
56−-- |
57−-- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of
58−-- | left: `a $ b $ c $ d x = a $ (b $ (c $ (d $ x))) = a (b (c (d x)))`
59−($) :: forall a b. (a -> b) -> a -> b
60−($) f x = f x
61−
62−-- | Applies an argument to a function.
63−-- |
64−-- | ```purescript
65−-- | products # filter isInStock # groupBy productCategory # length
66−-- | ```
67−-- |
68−-- | is equivalent to:
69−-- |
70−-- | ```purescript
71−-- | length (groupBy productCategory (filter isInStock products))
72−-- | ```
73−-- |
74−-- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of
75−-- | right: `x # a # b # c # d = (((x # a) # b) # c) # d = d (c (b (a x)))`
76−(#) :: forall a b. a -> (a -> b) -> b
77−(#) x f = f x
78−
79−-- | Flips the order of the arguments to a function of two arguments.
80−-- |
81−-- | ```purescript
82−-- | flip const 1 2 = const 2 1 = 2
83−-- | ```
84−flip :: forall a b c. (a -> b -> c) -> b -> a -> c
85−flip f b a = f a b
86−
87−-- | Returns its first argument and ignores its second.
88−-- |
89−-- | ```purescript
90−-- | const 1 "hello" = 1
91−-- | ```
92−const :: forall a b. a -> b -> a
93−const a _ = a
94−
95−-- | This function returns its first argument, and can be used to assert type
96−-- | equalities. This can be useful when types are otherwise ambiguous.
97−-- |
98−-- | ```purescript
99−-- | main = print $ [] `asTypeOf` [0]
100−-- | ```
101−-- |
102−-- | If instead, we had written `main = print []`, the type of the argument
103−-- | `[]` would have been ambiguous, resulting in a compile-time error.
104−asTypeOf :: forall a. a -> a -> a
105−asTypeOf x _ = x
106−
107−-- | An alias for `true`, which can be useful in guard clauses:
108−-- |
109−-- | ```purescript
110−-- | max x y | x >= y = x
111−-- | | otherwise = y
112−-- | ```
113−otherwise :: Boolean
114−otherwise = true
115−
116−-- | A `Semigroupoid` is similar to a [`Category`](#category) but does not
117−-- | require an identity element `id`, just composable morphisms.
118−-- |
119−-- | `Semigroupoid`s must satisfy the following law:
120−-- |
121−-- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
122−-- |
123−-- | One example of a `Semigroupoid` is the function type constructor `(->)`,
124−-- | with `(<<<)` defined as function composition.
125−class Semigroupoid a where
126− compose :: forall b c d. a c d -> a b c -> a b d
127−
128−instance semigroupoidFn :: Semigroupoid (->) where
129− compose f g x = f (g x)
130−
131−infixr 9 >>>
132−infixr 9 <<<
133−
134−-- | `(<<<)` is an alias for `compose`.
135−(<<<) :: forall a b c d. (Semigroupoid a) => a c d -> a b c -> a b d
136−(<<<) = compose
137−
138−-- | Forwards composition, or `(<<<)` with its arguments reversed.
139−(>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
140−(>>>) = flip compose
141−
142−-- | `Category`s consist of objects and composable morphisms between them, and
143−-- | as such are [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids`
144−-- | must have an identity element.
145−-- |
146−-- | Instances must satisfy the following law in addition to the
147−-- | `Semigroupoid` law:
148−-- |
149−-- | - Identity: `id <<< p = p <<< id = p`
150−class (Semigroupoid a) <= Category a where
151− id :: forall t. a t t
152−
153−instance categoryFn :: Category (->) where
154− id x = x
155−
156−-- | A `Functor` is a type constructor which supports a mapping operation
157−-- | `(<$>)`.
158−-- |
159−-- | `(<$>)` can be used to turn functions `a -> b` into functions
160−-- | `f a -> f b` whose argument and return types use the type constructor `f`
161−-- | to represent some computational context.
162−-- |
163−-- | Instances must satisfy the following laws:
164−-- |
165−-- | - Identity: `(<$>) id = id`
166−-- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
167−class Functor f where
168− map :: forall a b. (a -> b) -> f a -> f b
169−
170−instance functorFn :: Functor ((->) r) where
171− map = compose
172−
173−instance functorArray :: Functor Array where
174− map = arrayMap
175−
176−foreign import arrayMap :: forall a b. (a -> b) -> Array a -> Array b
177−
178−infixl 4 <$>
179−infixl 1 <#>
180−
181−-- | `(<$>)` is an alias for `map`
182−(<$>) :: forall f a b. (Functor f) => (a -> b) -> f a -> f b
183−(<$>) = map
184−
185−-- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
186−-- |
187−-- | ```purescript
188−-- | [1, 2, 3] <#> \n -> n * n
189−-- | ```
190−(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
191−(<#>) fa f = f <$> fa
192−
193−-- | The `void` function is used to ignore the type wrapped by a
194−-- | [`Functor`](#functor), replacing it with `Unit` and keeping only the type
195−-- | information provided by the type constructor itself.
196−-- |
197−-- | `void` is often useful when using `do` notation to change the return type
198−-- | of a monadic computation:
199−-- |
200−-- | ```purescript
201−-- | main = forE 1 10 \n -> void do
202−-- | print n
203−-- | print (n * n)
204−-- | ```
205−void :: forall f a. (Functor f) => f a -> f Unit
206−void fa = const unit <$> fa
207−
208−-- | The `Apply` class provides the `(<*>)` which is used to apply a function
209−-- | to an argument under a type constructor.
210−-- |
211−-- | `Apply` can be used to lift functions of two or more arguments to work on
212−-- | values wrapped with the type constructor `f`. It might also be understood
213−-- | in terms of the `lift2` function:
214−-- |
215−-- | ```purescript
216−-- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
217−-- | lift2 f a b = f <$> a <*> b
218−-- | ```
219−-- |
220−-- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts
221−-- | the function application operator `($)` to arguments wrapped with the
222−-- | type constructor `f`.
223−-- |
224−-- | Instances must satisfy the following law in addition to the `Functor`
225−-- | laws:
226−-- |
227−-- | - Associative composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
228−-- |
229−-- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
230−class (Functor f) <= Apply f where
231− apply :: forall a b. f (a -> b) -> f a -> f b
232−
233−instance applyFn :: Apply ((->) r) where
234− apply f g x = f x (g x)
235−
236−instance applyArray :: Apply Array where
237− apply = ap
238−
239−infixl 4 <*>
240−
241−-- | `(<*>)` is an alias for `apply`.
242−(<*>) :: forall f a b. (Apply f) => f (a -> b) -> f a -> f b
243−(<*>) = apply
244−
245−-- | The `Applicative` type class extends the [`Apply`](#apply) type class
246−-- | with a `pure` function, which can be used to create values of type `f a`
247−-- | from values of type `a`.
248−-- |
249−-- | Where [`Apply`](#apply) provides the ability to lift functions of two or
250−-- | more arguments to functions whose arguments are wrapped using `f`, and
251−-- | [`Functor`](#functor) provides the ability to lift functions of one
252−-- | argument, `pure` can be seen as the function which lifts functions of
253−-- | _zero_ arguments. That is, `Applicative` functors support a lifting
254−-- | operation for any number of function arguments.
255−-- |
256−-- | Instances must satisfy the following laws in addition to the `Apply`
257−-- | laws:
258−-- |
259−-- | - Identity: `(pure id) <*> v = v`
260−-- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
261−-- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
262−-- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
263−class (Apply f) <= Applicative f where
264− pure :: forall a. a -> f a
265−
266−instance applicativeFn :: Applicative ((->) r) where
267− pure = const
268−
269−instance applicativeArray :: Applicative Array where
270− pure x = [x]
271−
272−-- | `return` is an alias for `pure`.
273−return :: forall m a. (Applicative m) => a -> m a
274−return = pure
275−
276−-- | `liftA1` provides a default implementation of `(<$>)` for any
277−-- | [`Applicative`](#applicative) functor, without using `(<$>)` as provided
278−-- | by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass
279−-- | relationship.
280−-- |
281−-- | `liftA1` can therefore be used to write [`Functor`](#functor) instances
282−-- | as follows:
283−-- |
284−-- | ```purescript
285−-- | instance functorF :: Functor F where
286−-- | map = liftA1
287−-- | ```
288−liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
289−liftA1 f a = pure f <*> a
290−
291−-- | The `Bind` type class extends the [`Apply`](#apply) type class with a
292−-- | "bind" operation `(>>=)` which composes computations in sequence, using
293−-- | the return value of one computation to determine the next computation.
294−-- |
295−-- | The `>>=` operator can also be expressed using `do` notation, as follows:
296−-- |
297−-- | ```purescript
298−-- | x >>= f = do y <- x
299−-- | f y
300−-- | ```
301−-- |
302−-- | where the function argument of `f` is given the name `y`.
303−-- |
304−-- | Instances must satisfy the following law in addition to the `Apply`
305−-- | laws:
306−-- |
307−-- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
308−-- |
309−-- | Associativity tells us that we can regroup operations which use `do`
310−-- | notation so that we can unambiguously write, for example:
311−-- |
312−-- | ```purescript
313−-- | do x <- m1
314−-- | y <- m2 x
315−-- | m3 x y
316−-- | ```
317−class (Apply m) <= Bind m where
318− bind :: forall a b. m a -> (a -> m b) -> m b
319−
320−instance bindFn :: Bind ((->) r) where
321− bind m f x = f (m x) x
322−
323−instance bindArray :: Bind Array where
324− bind = arrayBind
325−
326−foreign import arrayBind :: forall a b. Array a -> (a -> Array b) -> Array b
327−
328−infixl 1 >>=
329−
330−-- | `(>>=)` is an alias for `bind`.
331−(>>=) :: forall m a b. (Bind m) => m a -> (a -> m b) -> m b
332−(>>=) = bind
333−
334−-- | The `Monad` type class combines the operations of the `Bind` and
335−-- | `Applicative` type classes. Therefore, `Monad` instances represent type
336−-- | constructors which support sequential composition, and also lifting of
337−-- | functions of arbitrary arity.
338−-- |
339−-- | Instances must satisfy the following laws in addition to the
340−-- | `Applicative` and `Bind` laws:
341−-- |
342−-- | - Left Identity: `pure x >>= f = f x`
343−-- | - Right Identity: `x >>= pure = x`
344−class (Applicative m, Bind m) <= Monad m
345−
346−instance monadFn :: Monad ((->) r)
347−instance monadArray :: Monad Array
348−
349−-- | `liftM1` provides a default implementation of `(<$>)` for any
350−-- | [`Monad`](#monad), without using `(<$>)` as provided by the
351−-- | [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
352−-- |
353−-- | `liftM1` can therefore be used to write [`Functor`](#functor) instances
354−-- | as follows:
355−-- |
356−-- | ```purescript
357−-- | instance functorF :: Functor F where
358−-- | map = liftM1
359−-- | ```
360−liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
361−liftM1 f a = do
362− a' <- a
363− return (f a')
364−
365−-- | `ap` provides a default implementation of `(<*>)` for any
366−-- | [`Monad`](#monad), without using `(<*>)` as provided by the
367−-- | [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
368−-- |
369−-- | `ap` can therefore be used to write [`Apply`](#apply) instances as
370−-- | follows:
371−-- |
372−-- | ```purescript
373−-- | instance applyF :: Apply F where
374−-- | apply = ap
375−-- | ```
376−ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
377−ap f a = do
378− f' <- f
379− a' <- a
380− return (f' a')
381−
382−-- | The `Semigroup` type class identifies an associative operation on a type.
383−-- |
384−-- | Instances are required to satisfy the following law:
385−-- |
386−-- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
387−-- |
388−-- | One example of a `Semigroup` is `String`, with `(<>)` defined as string
389−-- | concatenation.
390−class Semigroup a where
391− append :: a -> a -> a
392−
393−infixr 5 <>
394−infixr 5 ++
395−
396−-- | `(<>)` is an alias for `append`.
397−(<>) :: forall s. (Semigroup s) => s -> s -> s
398−(<>) = append
399−
400−-- | `(++)` is an alternative alias for `append`.
401−(++) :: forall s. (Semigroup s) => s -> s -> s
402−(++) = append
403−
404−instance semigroupString :: Semigroup String where
405− append = concatString
406−
407−instance semigroupUnit :: Semigroup Unit where
408− append _ _ = unit
409−
410−instance semigroupFn :: (Semigroup s') => Semigroup (s -> s') where
411− append f g = \x -> f x <> g x
412−
413−instance semigroupOrdering :: Semigroup Ordering where
414− append LT _ = LT
415− append GT _ = GT
416− append EQ y = y
417−
418−instance semigroupArray :: Semigroup (Array a) where
419− append = concatArray
420−
421−foreign import concatString :: String -> String -> String
422−foreign import concatArray :: forall a. Array a -> Array a -> Array a
423−
424−-- | The `Semiring` class is for types that support an addition and
425−-- | multiplication operation.
426−-- |
427−-- | Instances must satisfy the following laws:
428−-- |
429−-- | - Commutative monoid under addition:
430−-- | - Associativity: `(a + b) + c = a + (b + c)`
431−-- | - Identity: `zero + a = a + zero = a`
432−-- | - Commutative: `a + b = b + a`
433−-- | - Monoid under multiplication:
434−-- | - Associativity: `(a * b) * c = a * (b * c)`
435−-- | - Identity: `one * a = a * one = a`
436−-- | - Multiplication distributes over addition:
437−-- | - Left distributivity: `a * (b + c) = (a * b) + (a * c)`
438−-- | - Right distributivity: `(a + b) * c = (a * c) + (b * c)`
439−-- | - Annihiliation: `zero * a = a * zero = zero`
440−class Semiring a where
441− add :: a -> a -> a
442− zero :: a
443− mul :: a -> a -> a
444− one :: a
445−
446−instance semiringInt :: Semiring Int where
447− add = intAdd
448− zero = 0
449− mul = intMul
450− one = 1
451−
452−instance semiringNumber :: Semiring Number where
453− add = numAdd
454− zero = 0.0
455− mul = numMul
456− one = 1.0
457−
458−instance semiringUnit :: Semiring Unit where
459− add _ _ = unit
460− zero = unit
461− mul _ _ = unit
462− one = unit
463−
464−infixl 6 +
465−infixl 7 *
466−
467−-- | `(+)` is an alias for `add`.
468−(+) :: forall a. (Semiring a) => a -> a -> a
469−(+) = add
470−
471−-- | `(*)` is an alias for `mul`.
472−(*) :: forall a. (Semiring a) => a -> a -> a
473−(*) = mul
474−
475−foreign import intAdd :: Int -> Int -> Int
476−foreign import intMul :: Int -> Int -> Int
477−foreign import numAdd :: Number -> Number -> Number
478−foreign import numMul :: Number -> Number -> Number
479−
480−-- | The `Ring` class is for types that support addition, multiplication,
481−-- | and subtraction operations.
482−-- |
483−-- | Instances must satisfy the following law in addition to the `Semiring`
484−-- | laws:
485−-- |
486−-- | - Additive inverse: `a - a = (zero - a) + a = zero`
487−class (Semiring a) <= Ring a where
488− sub :: a -> a -> a
489−
490−instance ringInt :: Ring Int where
491− sub = intSub
492−
493−instance ringNumber :: Ring Number where
494− sub = numSub
495−
496−instance ringUnit :: Ring Unit where
497− sub _ _ = unit
498−
499−infixl 6 -
500−
501−-- | `(-)` is an alias for `sub`.
502−(-) :: forall a. (Ring a) => a -> a -> a
503−(-) = sub
504−
505−-- | `negate x` can be used as a shorthand for `zero - x`.
506−negate :: forall a. (Ring a) => a -> a
507−negate a = zero - a
508−
509−foreign import intSub :: Int -> Int -> Int
510−foreign import numSub :: Number -> Number -> Number
511−
512−-- | The `ModuloSemiring` class is for types that support addition,
513−-- | multiplication, division, and modulo (division remainder) operations.
514−-- |
515−-- | Instances must satisfy the following law in addition to the `Semiring`
516−-- | laws:
517−-- |
518−-- | - Remainder: `a / b * b + (a `mod` b) = a`
519−class (Semiring a) <= ModuloSemiring a where
520− div :: a -> a -> a
521− mod :: a -> a -> a
522−
523−instance moduloSemiringInt :: ModuloSemiring Int where
524− div = intDiv
525− mod = intMod
526−
527−instance moduloSemiringNumber :: ModuloSemiring Number where
528− div = numDiv
529− mod _ _ = 0.0
530−
531−instance moduloSemiringUnit :: ModuloSemiring Unit where
532− div _ _ = unit
533− mod _ _ = unit
534−
535−infixl 7 /
536−
537−-- | `(/)` is an alias for `div`.
538−(/) :: forall a. (ModuloSemiring a) => a -> a -> a
539−(/) = div
540−
541−foreign import intDiv :: Int -> Int -> Int
542−foreign import numDiv :: Number -> Number -> Number
543−foreign import intMod :: Int -> Int -> Int
544−
545−-- | A `Ring` where every nonzero element has a multiplicative inverse.
546−-- |
547−-- | Instances must satisfy the following law in addition to the `Ring` and
548−-- | `ModuloSemiring` laws:
549−-- |
550−-- | - Multiplicative inverse: `(one / x) * x = one`
551−-- |
552−-- | As a consequence of this ```a `mod` b = zero``` as no divide operation
553−-- | will have a remainder.
554−class (Ring a, ModuloSemiring a) <= DivisionRing a
555−
556−instance divisionRingNumber :: DivisionRing Number
557−instance divisionRingUnit :: DivisionRing Unit
558−
559−-- | The `Num` class is for types that are commutative fields.
560−-- |
561−-- | Instances must satisfy the following law in addition to the
562−-- | `DivisionRing` laws:
563−-- |
564−-- | - Commutative multiplication: `a * b = b * a`
565−class (DivisionRing a) <= Num a
566−
567−instance numNumber :: Num Number
568−instance numUnit :: Num Unit
569−
570−-- | The `Eq` type class represents types which support decidable equality.
571−-- |
572−-- | `Eq` instances should satisfy the following laws:
573−-- |
574−-- | - Reflexivity: `x == x = true`
575−-- | - Symmetry: `x == y = y == x`
576−-- | - Transitivity: if `x == y` and `y == z` then `x == z`
577−class Eq a where
578− eq :: a -> a -> Boolean
579−
580−infix 4 ==
581−infix 4 /=
582−
583−-- | `(==)` is an alias for `eq`. Tests whether one value is equal to another.
584−(==) :: forall a. (Eq a) => a -> a -> Boolean
585−(==) = eq
586−
587−-- | `(/=)` tests whether one value is _not equal_ to another. Shorthand for
588−-- | `not (x == y)`.
589−(/=) :: forall a. (Eq a) => a -> a -> Boolean
590−(/=) x y = not (x == y)
591−
592−instance eqBoolean :: Eq Boolean where
593− eq = refEq
594−
595−instance eqInt :: Eq Int where
596− eq = refEq
597−
598−instance eqNumber :: Eq Number where
599− eq = refEq
600−
601−instance eqChar :: Eq Char where
602− eq = refEq
603−
604−instance eqString :: Eq String where
605− eq = refEq
606−
607−instance eqUnit :: Eq Unit where
608− eq _ _ = true
609−
610−instance eqArray :: (Eq a) => Eq (Array a) where
611− eq = eqArrayImpl (==)
612−
613−instance eqOrdering :: Eq Ordering where
614− eq LT LT = true
615− eq GT GT = true
616− eq EQ EQ = true
617− eq _ _ = false
618−
619−foreign import refEq :: forall a. a -> a -> Boolean
620−foreign import refIneq :: forall a. a -> a -> Boolean
621−foreign import eqArrayImpl :: forall a. (a -> a -> Boolean) -> Array a -> Array a -> Boolean
622−
623−-- | The `Ordering` data type represents the three possible outcomes of
624−-- | comparing two values:
625−-- |
626−-- | `LT` - The first value is _less than_ the second.
627−-- | `GT` - The first value is _greater than_ the second.
628−-- | `EQ` - The first value is _equal to_ the second.
629−data Ordering = LT | GT | EQ
630−
631−-- | The `Ord` type class represents types which support comparisons with a
632−-- | _total order_.
633−-- |
634−-- | `Ord` instances should satisfy the laws of total orderings:
635−-- |
636−-- | - Reflexivity: `a <= a`
637−-- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
638−-- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
639−class (Eq a) <= Ord a where
640− compare :: a -> a -> Ordering
641−
642−instance ordBoolean :: Ord Boolean where
643− compare = unsafeCompare
644−
645−instance ordInt :: Ord Int where
646− compare = unsafeCompare
647−
648−instance ordNumber :: Ord Number where
649− compare = unsafeCompare
650−
651−instance ordString :: Ord String where
652− compare = unsafeCompare
653−
654−instance ordChar :: Ord Char where
655− compare = unsafeCompare
656−
657−instance ordUnit :: Ord Unit where
658− compare _ _ = EQ
659−
660−instance ordArray :: (Ord a) => Ord (Array a) where
661− compare xs ys = compare 0 $ ordArrayImpl (\x y -> case compare x y of
662− EQ -> 0
663− LT -> 1
664− GT -> -1) xs ys
665−
666−foreign import ordArrayImpl :: forall a. (a -> a -> Int) -> Array a -> Array a -> Int
667−
668−instance ordOrdering :: Ord Ordering where
669− compare LT LT = EQ
670− compare EQ EQ = EQ
671− compare GT GT = EQ
672− compare LT _ = LT
673− compare EQ LT = GT
674− compare EQ GT = LT
675− compare GT _ = GT
676−
677−infixl 4 <
678−infixl 4 >
679−infixl 4 <=
680−infixl 4 >=
681−
682−-- | Test whether one value is _strictly less than_ another.
683−(<) :: forall a. (Ord a) => a -> a -> Boolean
684−(<) a1 a2 = case a1 `compare` a2 of
685− LT -> true
686− _ -> false
687−
688−-- | Test whether one value is _strictly greater than_ another.
689−(>) :: forall a. (Ord a) => a -> a -> Boolean
690−(>) a1 a2 = case a1 `compare` a2 of
691− GT -> true
692− _ -> false
693−
694−-- | Test whether one value is _non-strictly less than_ another.
695−(<=) :: forall a. (Ord a) => a -> a -> Boolean
696−(<=) a1 a2 = case a1 `compare` a2 of
697− GT -> false
698− _ -> true
699−
700−-- | Test whether one value is _non-strictly greater than_ another.
701−(>=) :: forall a. (Ord a) => a -> a -> Boolean
702−(>=) a1 a2 = case a1 `compare` a2 of
703− LT -> false
704− _ -> true
705−
706−unsafeCompare :: forall a. a -> a -> Ordering
707−unsafeCompare = unsafeCompareImpl LT EQ GT
708−
709−foreign import unsafeCompareImpl :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
710−
711−-- | The `Bounded` type class represents types that are finite.
712−-- |
713−-- | Although there are no "internal" laws for `Bounded`, every value of `a`
714−-- | should be considered less than or equal to `top` by some means, and greater
715−-- | than or equal to `bottom`.
716−-- |
717−-- | The lack of explicit `Ord` constraint allows flexibility in the use of
718−-- | `Bounded` so it can apply to total and partially ordered sets, boolean
719−-- | algebras, etc.
720−class Bounded a where
721− top :: a
722− bottom :: a
723−
724−instance boundedBoolean :: Bounded Boolean where
725− top = true
726− bottom = false
727−
728−instance boundedUnit :: Bounded Unit where
729− top = unit
730− bottom = unit
731−
732−instance boundedOrdering :: Bounded Ordering where
733− top = GT
734− bottom = LT
735−
736−instance boundedInt :: Bounded Int where
737− top = 2147483647
738− bottom = -2147483648
739−
740−instance boundedFn :: (Bounded b) => Bounded (a -> b) where
741− top _ = top
742− bottom _ = bottom
743−
744−-- | The `BoundedOrd` type class represents totally ordered finite data types.
745−-- |
746−-- | Instances should satisfy the following law in addition to the `Ord` laws:
747−-- |
748−-- | - Ordering: `bottom <= a <= top`
749−class (Bounded a, Ord a) <= BoundedOrd a
750−
751−instance boundedOrdBoolean :: BoundedOrd Boolean where
752−instance boundedOrdUnit :: BoundedOrd Unit where
753−instance boundedOrdOrdering :: BoundedOrd Ordering where
754−instance boundedOrdInt :: BoundedOrd Int where
755−
756−-- | The `BooleanAlgebra` type class represents types that behave like boolean
757−-- | values.
758−-- |
759−-- | Instances should satisfy the following laws in addition to the `Bounded`
760−-- | laws:
761−-- |
762−-- | - Associativity:
763−-- | - `a || (b || c) = (a || b) || c`
764−-- | - `a && (b && c) = (a && b) && c`
765−-- | - Commutativity:
766−-- | - `a || b = b || a`
767−-- | - `a && b = b && a`
768−-- | - Distributivity:
769−-- | - `a && (b || c) = (a && b) || (a && c)`
770−-- | - `a || (b && c) = (a || b) && (a || c)`
771−-- | - Identity:
772−-- | - `a || bottom = a`
773−-- | - `a && top = a`
774−-- | - Idempotent:
775−-- | - `a || a = a`
776−-- | - `a && a = a`
777−-- | - Absorption:
778−-- | - `a || (a && b) = a`
779−-- | - `a && (a || b) = a`
780−-- | - Annhiliation:
781−-- | - `a || top = top`
782−-- | - Complementation:
783−-- | - `a && not a = bottom`
784−-- | - `a || not a = top`
785−class (Bounded a) <= BooleanAlgebra a where
786− conj :: a -> a -> a
787− disj :: a -> a -> a
788− not :: a -> a
789−
790−instance booleanAlgebraBoolean :: BooleanAlgebra Boolean where
791− conj = boolAnd
792− disj = boolOr
793− not = boolNot
794−
795−instance booleanAlgebraUnit :: BooleanAlgebra Unit where
796− conj _ _ = unit
797− disj _ _ = unit
798− not _ = unit
799−
800−instance booleanAlgebraFn :: (BooleanAlgebra b) => BooleanAlgebra (a -> b) where
801− conj fx fy a = fx a `conj` fy a
802− disj fx fy a = fx a `disj` fy a
803− not fx a = not (fx a)
804−
805−infixr 3 &&
806−infixr 2 ||
807−
808−-- | `(&&)` is an alias for `conj`.
809−(&&) :: forall a. (BooleanAlgebra a) => a -> a -> a
810−(&&) = conj
811−
812−-- | `(||)` is an alias for `disj`.
813−(||) :: forall a. (BooleanAlgebra a) => a -> a -> a
814−(||) = disj
815−
816−foreign import boolOr :: Boolean -> Boolean -> Boolean
817−foreign import boolAnd :: Boolean -> Boolean -> Boolean
818−foreign import boolNot :: Boolean -> Boolean
819−
820−-- | The `Show` type class represents those types which can be converted into
821−-- | a human-readable `String` representation.
822−-- |
823−-- | While not required, it is recommended that for any expression `x`, the
824−-- | string `show x` be executable PureScript code which evaluates to the same
825−-- | value as the expression `x`.
826−class Show a where
827− show :: a -> String
828−
829−instance showBoolean :: Show Boolean where
830− show true = "true"
831− show false = "false"
832−
833−instance showInt :: Show Int where
834− show = showIntImpl
835−
836−instance showNumber :: Show Number where
837− show = showNumberImpl
838−
839−instance showChar :: Show Char where
840− show = showCharImpl
841−
842−instance showString :: Show String where
843− show = showStringImpl
844−
845−instance showUnit :: Show Unit where
846− show _ = "unit"
847−
848−instance showArray :: (Show a) => Show (Array a) where
849− show = showArrayImpl show
850−
851−instance showOrdering :: Show Ordering where
852− show LT = "LT"
853− show GT = "GT"
854− show EQ = "EQ"
855−
856−foreign import showIntImpl :: Int -> String
857−foreign import showNumberImpl :: Number -> String
858−foreign import showCharImpl :: Char -> String
859−foreign import showStringImpl :: String -> String
860−foreign import showArrayImpl :: forall a. (a -> String) -> Array a -> String
tests/support/flattened/Test-Assert.jsdeleted−27
@@ -1,27 +0,0 @@
1−/* global exports */
2−"use strict";
3−
4−// module Test.Assert
5−
6−exports["assert'"] = function (message) {
7− return function (success) {
8− return function () {
9− if (!success) throw new Error(message);
10− return {};
11− };
12− };
13−};
14−
15−exports.checkThrows = function (fn) {
16− return function () {
17− try {
18− fn();
19− return false;
20− } catch (e) {
21− if (e instanceof Error) return true;
22− var err = new Error("Threw something other than an Error");
23− err.something = e;
24− throw err;
25− }
26− };
27−};
tests/support/flattened/Test-Assert.pursdeleted−32
@@ -1,32 +0,0 @@
1−module Test.Assert
2− ( assert'
3− , assert
4− , assertThrows
5− , assertThrows'
6− , ASSERT()
7− ) where
8−
9−import Control.Monad.Eff (Eff())
10−import Prelude
11−
12−-- | Assertion effect type.
13−foreign import data ASSERT :: !
14−
15−-- | Throws a runtime exception with message "Assertion failed" when the boolean
16−-- | value is false.
17−assert :: forall e. Boolean -> Eff (assert :: ASSERT | e) Unit
18−assert = assert' "Assertion failed"
19−
20−-- | Throws a runtime exception with the specified message when the boolean
21−-- | value is false.
22−foreign import assert' :: forall e. String -> Boolean -> Eff (assert :: ASSERT | e) Unit
23−
24−assertThrows :: forall e a. (Unit -> a) -> Eff (assert :: ASSERT | e) Unit
25−assertThrows = assertThrows' "Assertion failed: An error should have been thrown"
26−
27−assertThrows' :: forall e a. String -> (Unit -> a) -> Eff (assert :: ASSERT | e) Unit
28−assertThrows' msg fn =
29− checkThrows fn >>= assert' msg
30−
31−
32−foreign import checkThrows :: forall e a. (Unit -> a) -> Eff (assert :: ASSERT | e) Boolean