From 0bbd70a799fed521011d04ef06fc70be05a2d2fb Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Thu, 17 Mar 2016 12:16:26 +0000 Subject: [PATCH 1/2] Update for names in new prelude --- examples/failing/Do.purs | 4 +- examples/failing/SkolemEscape2.purs | 2 +- examples/failing/Superclasses5.purs | 3 +- examples/failing/TypeError.purs | 2 +- examples/manual/passing/Module.purs | 4 +- examples/manual/passing/TransitiveImport.purs | 4 +- examples/passing/1664.purs | 2 +- examples/passing/CaseInDo.purs | 4 +- examples/passing/CaseMultipleExpressions.purs | 4 +- examples/passing/Collatz.purs | 4 +- examples/passing/Console.purs | 2 +- examples/passing/ContextSimplification.purs | 2 +- examples/passing/DeepCase.purs | 2 +- examples/passing/Eff.purs | 4 +- examples/passing/EqOrd.purs | 2 +- examples/passing/ExtendedInfixOperators.purs | 2 +- examples/passing/Fib.purs | 2 +- examples/passing/FinalTagless.purs | 2 +- examples/passing/ImportHiding.purs | 2 +- .../InferRecFunWithConstrainedArgument.purs | 2 +- examples/passing/Let.purs | 14 +- examples/passing/Let2.purs | 2 +- examples/passing/ModuleExport.purs | 2 +- examples/passing/ModuleExportDupes.purs | 2 +- examples/passing/ModuleExportExcluded.purs | 2 +- examples/passing/ModuleExportQualified.purs | 2 +- examples/passing/ModuleExportSelf.purs | 2 +- examples/passing/MonadState.purs | 2 +- examples/passing/MultiArgFunctions.purs | 4 +- examples/passing/NestedTypeSynonyms.purs | 2 +- examples/passing/Newtype.purs | 10 +- examples/passing/ObjectGetter.purs | 2 +- examples/passing/ObjectUpdater.purs | 2 +- examples/passing/ObjectWildcards.purs | 6 +- examples/passing/OperatorInlining.purs | 41 +- examples/passing/Operators.purs | 6 +- examples/passing/OptionalQualified.purs | 2 +- examples/passing/Person.purs | 5 +- examples/passing/Rank2TypeSynonym.purs | 2 +- examples/passing/ReExportQualified.purs | 2 +- examples/passing/RowPolyInstanceContext.purs | 4 +- examples/passing/RuntimeScopeIssue.purs | 2 +- examples/passing/Superclasses1.purs | 2 +- examples/passing/Superclasses3.purs | 2 +- examples/passing/TCO.purs | 12 +- examples/passing/TailCall.purs | 2 +- examples/passing/TypeClasses.purs | 8 +- examples/passing/TypedBinders.purs | 10 +- examples/passing/UnicodeType.purs | 8 +- examples/passing/Unit.purs | 2 +- examples/passing/Where.purs | 14 +- psci/PSCi/Module.hs | 8 +- purescript.cabal | 8 +- .../CodeGen/JS/Optimizer/Inliner.hs | 40 +- src/Language/PureScript/Constants.hs | 19 +- .../PureScript/Sugar/TypeClasses/Deriving.hs | 53 +- tests/Main.hs | 13 - tests/TestPsci.hs | 33 +- tests/support/bower.json | 12 +- .../flattened/Control-Applicative.purs | 64 ++ tests/support/flattened/Control-Apply.js | 16 + tests/support/flattened/Control-Apply.purs | 78 ++ tests/support/flattened/Control-Bind.js | 13 + tests/support/flattened/Control-Bind.purs | 103 ++ tests/support/flattened/Control-Category.purs | 20 + .../flattened/Control-Monad-Eff-Class.purs | 27 +- .../flattened/Control-Monad-Eff-Console.js | 15 +- .../flattened/Control-Monad-Eff-Console.purs | 52 +- .../flattened/Control-Monad-Eff-Unsafe.js | 1 - .../flattened/Control-Monad-Eff-Unsafe.purs | 19 +- tests/support/flattened/Control-Monad-Eff.js | 3 +- .../support/flattened/Control-Monad-Eff.purs | 68 +- tests/support/flattened/Control-Monad-ST.purs | 56 +- tests/support/flattened/Control-Monad.purs | 63 ++ .../flattened/Control-Semigroupoid.purs | 24 + tests/support/flattened/Data-Boolean.purs | 10 + .../flattened/Data-BooleanAlgebra.purs | 20 + tests/support/flattened/Data-Bounded.js | 9 + tests/support/flattened/Data-Bounded.purs | 46 + .../flattened/Data-CommutativeRing.purs | 22 + tests/support/flattened/Data-Eq.js | 27 + tests/support/flattened/Data-Eq.purs | 51 + tests/support/flattened/Data-EuclideanRing.js | 26 + .../support/flattened/Data-EuclideanRing.purs | 47 + tests/support/flattened/Data-Field.purs | 24 + ...Function.js => Data-Function-Uncurried.js} | 3 +- .../flattened/Data-Function-Uncurried.purs | 102 ++ tests/support/flattened/Data-Function.purs | 178 ++-- tests/support/flattened/Data-Functor.js | 14 + tests/support/flattened/Data-Functor.purs | 72 ++ .../support/flattened/Data-HeytingAlgebra.js | 19 + .../flattened/Data-HeytingAlgebra.purs | 70 ++ tests/support/flattened/Data-Ord-Unsafe.js | 15 + tests/support/flattened/Data-Ord-Unsafe.purs | 15 + tests/support/flattened/Data-Ord.js | 41 + tests/support/flattened/Data-Ord.purs | 153 +++ tests/support/flattened/Data-Ordering.purs | 36 + tests/support/flattened/Data-Ring.js | 16 + tests/support/flattened/Data-Ring.purs | 35 + tests/support/flattened/Data-Semigroup.js | 15 + tests/support/flattened/Data-Semigroup.purs | 35 + tests/support/flattened/Data-Semiring.js | 29 + tests/support/flattened/Data-Semiring.purs | 51 + tests/support/flattened/Data-Show.js | 63 ++ tests/support/flattened/Data-Show.purs | 35 + tests/support/flattened/Data-Unit.js | 5 + tests/support/flattened/Data-Unit.purs | 17 + tests/support/flattened/Data-Void.purs | 13 + tests/support/flattened/Prelude.js | 228 ----- tests/support/flattened/Prelude.purs | 918 +----------------- tests/support/flattened/Test-Assert.js | 1 - tests/support/flattened/Test-Assert.purs | 35 +- tests/support/prelude | 2 +- 113 files changed, 2056 insertions(+), 1483 deletions(-) create mode 100644 tests/support/flattened/Control-Applicative.purs create mode 100644 tests/support/flattened/Control-Apply.js create mode 100644 tests/support/flattened/Control-Apply.purs create mode 100644 tests/support/flattened/Control-Bind.js create mode 100644 tests/support/flattened/Control-Bind.purs create mode 100644 tests/support/flattened/Control-Category.purs create mode 100644 tests/support/flattened/Control-Monad.purs create mode 100644 tests/support/flattened/Control-Semigroupoid.purs create mode 100644 tests/support/flattened/Data-Boolean.purs create mode 100644 tests/support/flattened/Data-BooleanAlgebra.purs create mode 100644 tests/support/flattened/Data-Bounded.js create mode 100644 tests/support/flattened/Data-Bounded.purs create mode 100644 tests/support/flattened/Data-CommutativeRing.purs create mode 100644 tests/support/flattened/Data-Eq.js create mode 100644 tests/support/flattened/Data-Eq.purs create mode 100644 tests/support/flattened/Data-EuclideanRing.js create mode 100644 tests/support/flattened/Data-EuclideanRing.purs create mode 100644 tests/support/flattened/Data-Field.purs rename tests/support/flattened/{Data-Function.js => Data-Function-Uncurried.js} (99%) create mode 100644 tests/support/flattened/Data-Function-Uncurried.purs create mode 100644 tests/support/flattened/Data-Functor.js create mode 100644 tests/support/flattened/Data-Functor.purs create mode 100644 tests/support/flattened/Data-HeytingAlgebra.js create mode 100644 tests/support/flattened/Data-HeytingAlgebra.purs create mode 100644 tests/support/flattened/Data-Ord-Unsafe.js create mode 100644 tests/support/flattened/Data-Ord-Unsafe.purs create mode 100644 tests/support/flattened/Data-Ord.js create mode 100644 tests/support/flattened/Data-Ord.purs create mode 100644 tests/support/flattened/Data-Ordering.purs create mode 100644 tests/support/flattened/Data-Ring.js create mode 100644 tests/support/flattened/Data-Ring.purs create mode 100644 tests/support/flattened/Data-Semigroup.js create mode 100644 tests/support/flattened/Data-Semigroup.purs create mode 100644 tests/support/flattened/Data-Semiring.js create mode 100644 tests/support/flattened/Data-Semiring.purs create mode 100644 tests/support/flattened/Data-Show.js create mode 100644 tests/support/flattened/Data-Show.purs create mode 100644 tests/support/flattened/Data-Unit.js create mode 100644 tests/support/flattened/Data-Unit.purs create mode 100644 tests/support/flattened/Data-Void.purs delete mode 100644 tests/support/flattened/Prelude.js diff --git a/examples/failing/Do.purs b/examples/failing/Do.purs index 7d648c2406..a0140bc56b 100644 --- a/examples/failing/Do.purs +++ b/examples/failing/Do.purs @@ -8,5 +8,5 @@ test1 = do let x = 1 test2 y = do x <- y -test3 = do return 1 - return 2 +test3 = do pure 1 + pure 2 diff --git a/examples/failing/SkolemEscape2.purs b/examples/failing/SkolemEscape2.purs index 6df2afe3f9..38d64cc332 100644 --- a/examples/failing/SkolemEscape2.purs +++ b/examples/failing/SkolemEscape2.purs @@ -7,4 +7,4 @@ import Control.Monad.ST test _ = do r <- runST (newSTRef 0) - return 0 + pure 0 diff --git a/examples/failing/Superclasses5.purs b/examples/failing/Superclasses5.purs index b93c5f4f16..0de8d4bf8b 100644 --- a/examples/failing/Superclasses5.purs +++ b/examples/failing/Superclasses5.purs @@ -3,6 +3,7 @@ module Main where import Prelude +import Control.Monad.Eff.Console (logShow) class Su a where su :: a -> a @@ -22,4 +23,4 @@ instance clNumber :: Cl Number where test :: forall a. (Cl a) => a -> Array a test x = su [cl x x] -main = Control.Monad.Eff.Console.print $ test 10.0 +main = logShow $ test 10.0 diff --git a/examples/failing/TypeError.purs b/examples/failing/TypeError.purs index 8e028b3772..1c5c980067 100644 --- a/examples/failing/TypeError.purs +++ b/examples/failing/TypeError.purs @@ -3,4 +3,4 @@ module Main where import Prelude -test = 1 ++ "A" +test = 1 <> "A" diff --git a/examples/manual/passing/Module.purs b/examples/manual/passing/Module.purs index a5dcea8f97..6d8d748a64 100644 --- a/examples/manual/passing/Module.purs +++ b/examples/manual/passing/Module.purs @@ -5,7 +5,7 @@ module M1 where data Foo = Foo String foo :: M1.Foo -> String - foo = \f -> case f of Foo s -> s ++ "foo" + foo = \f -> case f of Foo s -> s <> "foo" bar :: Foo -> String bar = foo @@ -21,7 +21,7 @@ module M2 where baz = M1.foo match :: M1.Foo -> String - match = \f -> case f of M1.Foo s -> s ++ "foo" + match = \f -> case f of M1.Foo s -> s <> "foo" module Main where diff --git a/examples/manual/passing/TransitiveImport.purs b/examples/manual/passing/TransitiveImport.purs index 0274cbe250..524e19cf35 100644 --- a/examples/manual/passing/TransitiveImport.purs +++ b/examples/manual/passing/TransitiveImport.purs @@ -19,6 +19,6 @@ module Main where import Control.Monad.Eff.Console main = do - print (middle unit) + logShow (middle unit) trace "Done" - return unit + pure unit diff --git a/examples/passing/1664.purs b/examples/passing/1664.purs index 40260c78ca..35a17eddab 100644 --- a/examples/passing/1664.purs +++ b/examples/passing/1664.purs @@ -11,6 +11,6 @@ newtype IdentityEff e a = IdentityEff (Eff e (Identity a)) test :: forall e a. IdentityEff e a -> IdentityEff e Unit test (IdentityEff action) = IdentityEff $ do (Identity x :: Identity _) <- action - return $ Identity unit + pure $ Identity unit main = log "Done" diff --git a/examples/passing/CaseInDo.purs b/examples/passing/CaseInDo.purs index 574b69424e..9282c7a130 100644 --- a/examples/passing/CaseInDo.purs +++ b/examples/passing/CaseInDo.purs @@ -5,13 +5,13 @@ import Control.Monad.Eff.Console import Control.Monad.Eff doIt :: forall eff. Eff eff Boolean -doIt = return true +doIt = pure true set = do log "Testing..." case 0 of 0 -> doIt - _ -> return false + _ -> pure false main = do b <- set diff --git a/examples/passing/CaseMultipleExpressions.purs b/examples/passing/CaseMultipleExpressions.purs index 763a425cf6..40b0d30b87 100644 --- a/examples/passing/CaseMultipleExpressions.purs +++ b/examples/passing/CaseMultipleExpressions.purs @@ -5,13 +5,13 @@ import Control.Monad.Eff.Console import Control.Monad.Eff doIt :: forall eff. Eff eff Boolean -doIt = return true +doIt = pure true set = do log "Testing..." case 42, 10 of 42, 10 -> doIt - _ , _ -> return false + _ , _ -> pure false main = do b <- set diff --git a/examples/passing/Collatz.purs b/examples/passing/Collatz.purs index 80a3d1ecca..626d318016 100644 --- a/examples/passing/Collatz.purs +++ b/examples/passing/Collatz.purs @@ -12,7 +12,7 @@ collatz n = runPure (runST (do modifySTRef count $ (+) 1 m <- readSTRef r writeSTRef r $ if m `mod` 2 == 0 then m / 2 else 3 * m + 1 - return $ m == 1 + pure $ m == 1 readSTRef count)) -main = Control.Monad.Eff.Console.print $ collatz 1000 +main = Control.Monad.Eff.Console.logShow $ collatz 1000 diff --git a/examples/passing/Console.purs b/examples/passing/Console.purs index a828773d01..3d84ec7490 100644 --- a/examples/passing/Console.purs +++ b/examples/passing/Console.purs @@ -5,7 +5,7 @@ import Control.Monad.Eff import Control.Monad.Eff.Console replicateM_ :: forall m a. (Monad m) => Number -> m a -> m {} -replicateM_ 0.0 _ = return {} +replicateM_ 0.0 _ = pure {} replicateM_ n act = do act replicateM_ (n - 1.0) act diff --git a/examples/passing/ContextSimplification.purs b/examples/passing/ContextSimplification.purs index 88c5835281..f6becb9267 100644 --- a/examples/passing/ContextSimplification.purs +++ b/examples/passing/ContextSimplification.purs @@ -8,6 +8,6 @@ shout = log <<< (<> "!") <<< show -- Here, we should simplify the context so that only one Show -- constraint is added. usesShowTwice true = shout -usesShowTwice false = print +usesShowTwice false = logShow main = usesShowTwice true "Done" diff --git a/examples/passing/DeepCase.purs b/examples/passing/DeepCase.purs index dce5f23c6c..56be49c6eb 100644 --- a/examples/passing/DeepCase.purs +++ b/examples/passing/DeepCase.purs @@ -12,4 +12,4 @@ f x y = x -> 1.0 + x * x in g + x + y -main = print $ f 1.0 10.0 +main = logShow $ f 1.0 10.0 diff --git a/examples/passing/Eff.purs b/examples/passing/Eff.purs index 3d7c2cd2c0..77b9af2f3a 100644 --- a/examples/passing/Eff.purs +++ b/examples/passing/Eff.purs @@ -21,5 +21,5 @@ test3 = pureST (do main = do test1 - Control.Monad.Eff.Console.print test2 - Control.Monad.Eff.Console.print test3 + Control.Monad.Eff.Console.logShow test2 + Control.Monad.Eff.Console.logShow test3 diff --git a/examples/passing/EqOrd.purs b/examples/passing/EqOrd.purs index 9ed10b2a3e..cc2c9472f9 100644 --- a/examples/passing/EqOrd.purs +++ b/examples/passing/EqOrd.purs @@ -12,4 +12,4 @@ instance ordPair :: (Ord a, Ord b) => Ord (Pair a b) where instance eqPair :: (Eq a, Eq b) => Eq (Pair a b) where eq (Pair a1 b1) (Pair a2 b2) = a1 == a2 && b1 == b2 -main = Control.Monad.Eff.Console.print $ Pair 1.0 2.0 == Pair 1.0 2.0 +main = Control.Monad.Eff.Console.logShow $ Pair 1.0 2.0 == Pair 1.0 2.0 diff --git a/examples/passing/ExtendedInfixOperators.purs b/examples/passing/ExtendedInfixOperators.purs index 276d7d9d70..d70c40be1b 100644 --- a/examples/passing/ExtendedInfixOperators.purs +++ b/examples/passing/ExtendedInfixOperators.purs @@ -11,4 +11,4 @@ null _ = false test = [1.0, 2.0, 3.0] `comparing null` [4.0, 5.0, 6.0] main = do - Control.Monad.Eff.Console.print test + Control.Monad.Eff.Console.logShow test diff --git a/examples/passing/Fib.purs b/examples/passing/Fib.purs index bf6d5223df..6c3fcf1e95 100644 --- a/examples/passing/Fib.purs +++ b/examples/passing/Fib.purs @@ -12,4 +12,4 @@ main = runST (do n2' <- readSTRef n2 writeSTRef n2 $ n1' + n2' writeSTRef n1 n2' - Control.Monad.Eff.Console.print n2') + Control.Monad.Eff.Console.logShow n2') diff --git a/examples/passing/FinalTagless.purs b/examples/passing/FinalTagless.purs index 5347153759..3194fd1972 100644 --- a/examples/passing/FinalTagless.purs +++ b/examples/passing/FinalTagless.purs @@ -19,4 +19,4 @@ runId (Id a) = a three :: Expr Number three = add (num 1.0) (num 2.0) -main = Control.Monad.Eff.Console.print $ runId three +main = Control.Monad.Eff.Console.logShow $ runId three diff --git a/examples/passing/ImportHiding.purs b/examples/passing/ImportHiding.purs index 4abac7a82e..8cc0cf8d6e 100644 --- a/examples/passing/ImportHiding.purs +++ b/examples/passing/ImportHiding.purs @@ -15,4 +15,4 @@ class Show a where data Unit = X | Y main = do - print show + logShow show diff --git a/examples/passing/InferRecFunWithConstrainedArgument.purs b/examples/passing/InferRecFunWithConstrainedArgument.purs index 2a10977698..6c8d88927f 100644 --- a/examples/passing/InferRecFunWithConstrainedArgument.purs +++ b/examples/passing/InferRecFunWithConstrainedArgument.purs @@ -5,4 +5,4 @@ import Prelude test 100.0 = 100.0 test n = test(1.0 + n) -main = Control.Monad.Eff.Console.print $ test 0.0 +main = Control.Monad.Eff.Console.logShow $ test 0.0 diff --git a/examples/passing/Let.purs b/examples/passing/Let.purs index d1aac9d023..6e15774355 100644 --- a/examples/passing/Let.purs +++ b/examples/passing/Let.purs @@ -44,10 +44,10 @@ test10 _ = in f 10.0 main = do - Control.Monad.Eff.Console.print (test1 1.0) - Control.Monad.Eff.Console.print (test2 1.0 2.0) - Control.Monad.Eff.Console.print test3 - Control.Monad.Eff.Console.print test4 - Control.Monad.Eff.Console.print test5 - Control.Monad.Eff.Console.print test7 - Control.Monad.Eff.Console.print (test8 100.0) + Control.Monad.Eff.Console.logShow (test1 1.0) + Control.Monad.Eff.Console.logShow (test2 1.0 2.0) + Control.Monad.Eff.Console.logShow test3 + Control.Monad.Eff.Console.logShow test4 + Control.Monad.Eff.Console.logShow test5 + Control.Monad.Eff.Console.logShow test7 + Control.Monad.Eff.Console.logShow (test8 100.0) diff --git a/examples/passing/Let2.purs b/examples/passing/Let2.purs index 8da1344682..e43ab43c65 100644 --- a/examples/passing/Let2.purs +++ b/examples/passing/Let2.purs @@ -14,4 +14,4 @@ test = x = f 1.0 in not x -main = Control.Monad.Eff.Console.print test +main = Control.Monad.Eff.Console.logShow test diff --git a/examples/passing/ModuleExport.purs b/examples/passing/ModuleExport.purs index 6c283e91e3..1c891fd087 100644 --- a/examples/passing/ModuleExport.purs +++ b/examples/passing/ModuleExport.purs @@ -6,4 +6,4 @@ module Main where import A main = do - print (show 1.0) + logShow (show 1.0) diff --git a/examples/passing/ModuleExportDupes.purs b/examples/passing/ModuleExportDupes.purs index 72f807bf55..baef27c328 100644 --- a/examples/passing/ModuleExportDupes.purs +++ b/examples/passing/ModuleExportDupes.purs @@ -16,4 +16,4 @@ module Main where import Prelude main = do - print (show 1.0) + logShow (show 1.0) diff --git a/examples/passing/ModuleExportExcluded.purs b/examples/passing/ModuleExportExcluded.purs index fd0130a8b5..a84878a917 100644 --- a/examples/passing/ModuleExportExcluded.purs +++ b/examples/passing/ModuleExportExcluded.purs @@ -11,4 +11,4 @@ module Main where otherwise = false main = do - print "1.0" + logShow "1.0" diff --git a/examples/passing/ModuleExportQualified.purs b/examples/passing/ModuleExportQualified.purs index 88fa20edf5..4da8b11916 100644 --- a/examples/passing/ModuleExportQualified.purs +++ b/examples/passing/ModuleExportQualified.purs @@ -6,4 +6,4 @@ module Main where import qualified A as B main = do - print (B.show 1.0) + logShow (B.show 1.0) diff --git a/examples/passing/ModuleExportSelf.purs b/examples/passing/ModuleExportSelf.purs index cc2a0017a2..2812eda611 100644 --- a/examples/passing/ModuleExportSelf.purs +++ b/examples/passing/ModuleExportSelf.purs @@ -11,4 +11,4 @@ module Main where bar = true main = do - print (show bar) + logShow (show bar) diff --git a/examples/passing/MonadState.purs b/examples/passing/MonadState.purs index 8d64394be1..9777157b56 100644 --- a/examples/passing/MonadState.purs +++ b/examples/passing/MonadState.purs @@ -58,4 +58,4 @@ modify f = same :: forall a. (a -> a) -> (a -> a) same = id -main = print $ runState 0 (modify (+ 1)) +main = logShow $ runState 0 (modify (+ 1)) diff --git a/examples/passing/MultiArgFunctions.purs b/examples/passing/MultiArgFunctions.purs index 999d527776..b6b1b3208c 100644 --- a/examples/passing/MultiArgFunctions.purs +++ b/examples/passing/MultiArgFunctions.purs @@ -1,7 +1,7 @@ module Main where import Prelude -import Data.Function +import Data.Function.Uncurried import Control.Monad.Eff import Control.Monad.Eff.Console @@ -23,5 +23,5 @@ main = do runFn8 (mkFn8 $ \a b c d e f g h -> log $ show [a, b, c, d, e, f, g, h]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 runFn9 (mkFn9 $ \a b c d e f g h i -> log $ show [a, b, c, d, e, f, g, h, i]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 runFn10 (mkFn10 $ \a b c d e f g h i j-> log $ show [a, b, c, d, e, f, g, h, i, j]) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 - print $ runFn2 g 0.0 0.0 + logShow $ runFn2 g 0.0 0.0 log "Done!" diff --git a/examples/passing/NestedTypeSynonyms.purs b/examples/passing/NestedTypeSynonyms.purs index abb9ea7a5e..b55bf04d26 100644 --- a/examples/passing/NestedTypeSynonyms.purs +++ b/examples/passing/NestedTypeSynonyms.purs @@ -8,4 +8,4 @@ type Y = X -> X fn :: Y fn a = a -main = Control.Monad.Eff.Console.print (fn "Done") +main = Control.Monad.Eff.Console.logShow (fn "Done") diff --git a/examples/passing/Newtype.purs b/examples/passing/Newtype.purs index c9edbda825..43016b2568 100644 --- a/examples/passing/Newtype.purs +++ b/examples/passing/Newtype.purs @@ -7,17 +7,17 @@ import Control.Monad.Eff.Console newtype Thing = Thing String instance showThing :: Show Thing where - show (Thing x) = "Thing " ++ show x + show (Thing x) = "Thing " <> show x newtype Box a = Box a instance showBox :: (Show a) => Show (Box a) where - show (Box x) = "Box " ++ show x + show (Box x) = "Box " <> show x apply f x = f x main = do - print $ Thing "hello" - print $ Box 42.0 - print $ apply Box 9000.0 + logShow $ Thing "hello" + logShow $ Box 42.0 + logShow $ apply Box 9000.0 log "Done" diff --git a/examples/passing/ObjectGetter.purs b/examples/passing/ObjectGetter.purs index addb57f7de..ff71b702b4 100644 --- a/examples/passing/ObjectGetter.purs +++ b/examples/passing/ObjectGetter.purs @@ -7,7 +7,7 @@ getX = _.x point = { x: 1.0, y: 0.0 } main = do - Control.Monad.Eff.Console.print $ getX point + Control.Monad.Eff.Console.logShow $ getX point Control.Monad.Eff.Console.log $ _." 123 string Prop Name " { " 123 string Prop Name ": "OK" } Control.Monad.Eff.Console.log $ (_.x >>> _.y) { x: { y: "Nested" } } Control.Monad.Eff.Console.log $ _.value { value: "Done!" } diff --git a/examples/passing/ObjectUpdater.purs b/examples/passing/ObjectUpdater.purs index 17246c603d..8070beda9c 100644 --- a/examples/passing/ObjectUpdater.purs +++ b/examples/passing/ObjectUpdater.purs @@ -6,7 +6,7 @@ import Control.Monad.Eff.Console import Test.Assert getValue :: forall e. Eff (| e) Boolean -getValue = return true +getValue = pure true main = do let record = { value: false } diff --git a/examples/passing/ObjectWildcards.purs b/examples/passing/ObjectWildcards.purs index 5a0d4c8b87..cc9f6926d6 100644 --- a/examples/passing/ObjectWildcards.purs +++ b/examples/passing/ObjectWildcards.purs @@ -8,13 +8,13 @@ import Test.Assert mkRecord = { foo: _, bar: _, baz: "baz" } getValue :: forall e. Eff (| e) Boolean -getValue = return true +getValue = pure true main = do obj <- { value: _ } <$> getValue - print obj.value + logShow obj.value let x = 1.0 - point <- { x: _, y: x } <$> return 2.0 + point <- { x: _, y: x } <$> pure 2.0 assert $ point.x == 2.0 assert $ point.y == 1.0 log (mkRecord 1.0 "Done!").bar diff --git a/examples/passing/OperatorInlining.purs b/examples/passing/OperatorInlining.purs index 172babd0e3..90386427fb 100644 --- a/examples/passing/OperatorInlining.purs +++ b/examples/passing/OperatorInlining.purs @@ -6,42 +6,41 @@ import Control.Monad.Eff.Console main = do -- semiringNumber - print (1.0 + 2.0) - print (1.0 * 2.0) + logShow (1.0 + 2.0) + logShow (1.0 * 2.0) -- ringNumber - print (1.0 - 2.0) - print (negate 1.0) + logShow (1.0 - 2.0) + logShow (negate 1.0) -- moduleSemiringNumber - print (1.0 / 2.0) + logShow (1.0 / 2.0) -- ordNumber - print (1.0 > 2.0) - print (1.0 < 2.0) - print (1.0 <= 2.0) - print (1.0 >= 2.0) - print (1.0 == 2.0) + logShow (1.0 > 2.0) + logShow (1.0 < 2.0) + logShow (1.0 <= 2.0) + logShow (1.0 >= 2.0) + logShow (1.0 == 2.0) -- eqNumber - print (1.0 == 2.0) - print (1.0 /= 2.0) + logShow (1.0 == 2.0) + logShow (1.0 /= 2.0) -- eqString - print ("foo" == "bar") - print ("foo" /= "bar") + logShow ("foo" == "bar") + logShow ("foo" /= "bar") -- eqBoolean - print (true == false) - print (true /= false) + logShow (true == false) + logShow (true /= false) -- semigroupString - print ("foo" ++ "bar") - print ("foo" <> "bar") + logShow ("foo" <> "bar") -- latticeBoolean - print (top && true) - print (bottom || false) + logShow (top && true) + logShow (bottom || false) -- complementedLatticeBoolean - print (not true) + logShow (not true) diff --git a/examples/passing/Operators.purs b/examples/passing/Operators.purs index 0d6d86ffea..3e16cbbc12 100644 --- a/examples/passing/Operators.purs +++ b/examples/passing/Operators.purs @@ -8,9 +8,9 @@ import Control.Monad.Eff.Console (?!) x _ = x bar :: String -> String -> String -bar = \s1 s2 -> s1 ++ s2 +bar = \s1 s2 -> s1 <> s2 -test1 :: forall n. (Num n) => n -> n -> (n -> n -> n) -> n +test1 :: forall n. (Semiring n) => n -> n -> (n -> n -> n) -> n test1 x y z = x * y + z x y test2 = (\x -> x.foo false) { foo : \_ -> 1.0 } @@ -31,7 +31,7 @@ test5 = 1.0 %% 2.0 %% 3.0 test6 = ((\x -> x) `k` 2.0) 3.0 (<+>) :: String -> String -> String -(<+>) = \s1 s2 -> s1 ++ s2 +(<+>) = \s1 s2 -> s1 <> s2 test7 = "Hello" <+> "World!" diff --git a/examples/passing/OptionalQualified.purs b/examples/passing/OptionalQualified.purs index fccfd7ae4b..30256f3ea1 100644 --- a/examples/passing/OptionalQualified.purs +++ b/examples/passing/OptionalQualified.purs @@ -9,5 +9,5 @@ import Control.Monad.Eff.Console as Console bind = P.bind main = do - message <- P.return "success!" + message <- P.pure "success!" Console.log message diff --git a/examples/passing/Person.purs b/examples/passing/Person.purs index fa3384e597..fd0e4f9806 100644 --- a/examples/passing/Person.purs +++ b/examples/passing/Person.purs @@ -1,11 +1,12 @@ module Main where import Prelude +import Control.Monad.Eff.Console (log) data Person = Person { name :: String, age :: Number } showPerson :: Person -> String showPerson = \p -> case p of - Person o -> o.name ++ ", aged " ++ show o.age + Person o -> o.name <> ", aged " <> show o.age -main = Control.Monad.Eff.Console.log "Done" +main = log "Done" diff --git a/examples/passing/Rank2TypeSynonym.purs b/examples/passing/Rank2TypeSynonym.purs index a1977da4b0..58b1e8c208 100644 --- a/examples/passing/Rank2TypeSynonym.purs +++ b/examples/passing/Rank2TypeSynonym.purs @@ -13,4 +13,4 @@ bar = foo 3.0 main = do x <- bar - Control.Monad.Eff.Console.print x + Control.Monad.Eff.Console.logShow x diff --git a/examples/passing/ReExportQualified.purs b/examples/passing/ReExportQualified.purs index cf1c037cf8..f763566ccf 100644 --- a/examples/passing/ReExportQualified.purs +++ b/examples/passing/ReExportQualified.purs @@ -13,4 +13,4 @@ module Main where import Prelude import C - main = Control.Monad.Eff.Console.log (x ++ y) + main = Control.Monad.Eff.Console.log (x <> y) diff --git a/examples/passing/RowPolyInstanceContext.purs b/examples/passing/RowPolyInstanceContext.purs index f0543af36a..0a232f9dd4 100644 --- a/examples/passing/RowPolyInstanceContext.purs +++ b/examples/passing/RowPolyInstanceContext.purs @@ -11,10 +11,10 @@ instance st :: T s (S s) where state f = S $ \s -> { new: f s, ret: unit } test1 :: forall r . S { foo :: String | r } Unit -test1 = state $ \o -> o { foo = o.foo ++ "!" } +test1 = state $ \o -> o { foo = o.foo <> "!" } test2 :: forall m r . (T { foo :: String | r } m) => m Unit -test2 = state $ \o -> o { foo = o.foo ++ "!" } +test2 = state $ \o -> o { foo = o.foo <> "!" } main = do let t1 = test1 diff --git a/examples/passing/RuntimeScopeIssue.purs b/examples/passing/RuntimeScopeIssue.purs index f6800c81b9..b83e030517 100644 --- a/examples/passing/RuntimeScopeIssue.purs +++ b/examples/passing/RuntimeScopeIssue.purs @@ -16,4 +16,4 @@ instance bNumber :: B Number where b 0.0 = false b n = a (n - 1.0) -main = Control.Monad.Eff.Console.print $ a 10.0 +main = Control.Monad.Eff.Console.logShow $ a 10.0 diff --git a/examples/passing/Superclasses1.purs b/examples/passing/Superclasses1.purs index cdf075f0fb..915e06483b 100644 --- a/examples/passing/Superclasses1.purs +++ b/examples/passing/Superclasses1.purs @@ -17,4 +17,4 @@ instance clNumber :: Cl Number where test :: forall a. (Cl a) => a -> a test a = su (cl a a) -main = Control.Monad.Eff.Console.print $ test 10.0 +main = Control.Monad.Eff.Console.logShow $ test 10.0 diff --git a/examples/passing/Superclasses3.purs b/examples/passing/Superclasses3.purs index d1135a0bcb..14198645a5 100644 --- a/examples/passing/Superclasses3.purs +++ b/examples/passing/Superclasses3.purs @@ -28,7 +28,7 @@ instance applyMTrace :: Apply MTrace where apply = ap instance applicativeMTrace :: Applicative MTrace where - pure = MTrace <<< return + pure = MTrace <<< pure instance bindMTrace :: Bind MTrace where bind m f = MTrace (runMTrace m >>= (runMTrace <<< f)) diff --git a/examples/passing/TCO.purs b/examples/passing/TCO.purs index 85671785f3..74bd674e18 100644 --- a/examples/passing/TCO.purs +++ b/examples/passing/TCO.purs @@ -1,16 +1,16 @@ module Main where import Prelude -import Control.Monad.Eff.Console (print) +import Control.Monad.Eff.Console (logShow) main = do let f x = x + 1 let v = 0 - print (applyN 0 f v) - print (applyN 1 f v) - print (applyN 2 f v) - print (applyN 3 f v) - print (applyN 4 f v) + logShow (applyN 0 f v) + logShow (applyN 1 f v) + logShow (applyN 2 f v) + logShow (applyN 3 f v) + logShow (applyN 4 f v) applyN :: forall a. Int -> (a -> a) -> a -> a applyN = go id diff --git a/examples/passing/TailCall.purs b/examples/passing/TailCall.purs index 1fad42378b..9e65a3f930 100644 --- a/examples/passing/TailCall.purs +++ b/examples/passing/TailCall.purs @@ -14,4 +14,4 @@ loop x = loop (x + 1.0) notATailCall = \x -> (\notATailCall -> notATailCall x) (\x -> x) -main = Control.Monad.Eff.Console.print (test 0.0 (1.0 `C` (2.0 `C` (3.0 `C` N)))) +main = Control.Monad.Eff.Console.logShow (test 0.0 (1.0 `C` (2.0 `C` (3.0 `C` N)))) diff --git a/examples/passing/TypeClasses.purs b/examples/passing/TypeClasses.purs index 1dfdf51fc7..96c6351ca2 100644 --- a/examples/passing/TypeClasses.purs +++ b/examples/passing/TypeClasses.purs @@ -17,7 +17,7 @@ test8 = \_ -> show $ "testing" data Data a = Data a instance showData :: (Prelude.Show a) => Prelude.Show (Data a) where - show (Data a) = "Data (" ++ show a ++ ")" + show (Data a) = "Data (" <> show a <> ")" test3 = \_ -> show (Data "testing") @@ -53,9 +53,9 @@ instance bindMaybe :: Bind Maybe where instance monadMaybe :: Monad Maybe test4 :: forall a m. (Monad m) => a -> m Number -test4 = \_ -> return 1.0 +test4 = \_ -> pure 1.0 -test5 = \_ -> Just 1.0 >>= \n -> return (n + 1.0) +test5 = \_ -> Just 1.0 >>= \n -> pure (n + 1.0) ask r = r @@ -63,7 +63,7 @@ runReader r f = f r test9 _ = runReader 0.0 $ do n <- ask - return $ n + 1.0 + pure $ n + 1.0 main = Control.Monad.Eff.Console.log (test7 "Done") diff --git a/examples/passing/TypedBinders.purs b/examples/passing/TypedBinders.purs index 6f8ca7b6d5..ea63815dac 100644 --- a/examples/passing/TypedBinders.purs +++ b/examples/passing/TypedBinders.purs @@ -38,20 +38,20 @@ modify f = do test :: Tuple String String test = runState "" $ do - modify $ (++) "World!" - modify $ (++) "Hello, " + modify $ (<>) "World!" + modify $ (<>) "Hello, " str :: String <- get - return str + pure str test2 :: (Int -> Int) -> Int test2 = (\(f :: Int -> Int) -> f 10) -test3 :: Int -> Boolean +test3 :: Int -> Boolean test3 n = case n of (0 :: Int) -> true _ -> false -test4 :: Tuple Int Int -> Tuple Int Int +test4 :: Tuple Int Int -> Tuple Int Int test4 = (\(Tuple a b :: Tuple Int Int) -> Tuple b a) type Int1 = Int diff --git a/examples/passing/UnicodeType.purs b/examples/passing/UnicodeType.purs index 7e4ecb9ccd..a65d4a30d8 100644 --- a/examples/passing/UnicodeType.purs +++ b/examples/passing/UnicodeType.purs @@ -10,13 +10,13 @@ class (Monad m) <= Monad2 m where f ∷ ∀ m. Monad m ⇒ Int → m Int f n = do - n' ← return n - return n' + n' ← pure n + pure n' f' :: forall m. Monad m => Int -> m Int f' n = do - n' <- return n - return n' + n' <- pure n + pure n' (←→) a b = a ←→ b diff --git a/examples/passing/Unit.purs b/examples/passing/Unit.purs index 5e555283b1..808cd5ffbe 100644 --- a/examples/passing/Unit.purs +++ b/examples/passing/Unit.purs @@ -3,4 +3,4 @@ module Main where import Prelude import Control.Monad.Eff.Console -main = print (const unit $ "Hello world") +main = logShow (const unit $ "Hello world") diff --git a/examples/passing/Where.purs b/examples/passing/Where.purs index 942255fe5f..b090ed34a2 100644 --- a/examples/passing/Where.purs +++ b/examples/passing/Where.purs @@ -40,10 +40,10 @@ test7 x = go x go y = go $ (y + x / y) / 2.0 main = do - Control.Monad.Eff.Console.print (test1 1.0) - Control.Monad.Eff.Console.print (test2 1.0 2.0) - Control.Monad.Eff.Console.print test3 - Control.Monad.Eff.Console.print test4 - Control.Monad.Eff.Console.print test5 - Control.Monad.Eff.Console.print test6 - Control.Monad.Eff.Console.print (test7 100.0) + Control.Monad.Eff.Console.logShow (test1 1.0) + Control.Monad.Eff.Console.logShow (test2 1.0 2.0) + Control.Monad.Eff.Console.logShow test3 + Control.Monad.Eff.Console.logShow test4 + Control.Monad.Eff.Console.logShow test5 + Control.Monad.Eff.Console.logShow test6 + Control.Monad.Eff.Console.logShow (test7 100.0) diff --git a/psci/PSCi/Module.hs b/psci/PSCi/Module.hs index ead2c0057a..6766d8ea2f 100644 --- a/psci/PSCi/Module.hs +++ b/psci/PSCi/Module.hs @@ -24,15 +24,15 @@ supportModule = [ "module S where" , "" , "import Prelude" - , "import Control.Monad.Eff" - , "import Control.Monad.Eff.Console" - , "import Control.Monad.Eff.Unsafe" + , "import Control.Monad.Eff (Eff)" + , "import Control.Monad.Eff.Console (CONSOLE, logShow)" + , "import Control.Monad.Eff.Unsafe (unsafeInterleaveEff)" , "" , "class Eval a where" , " eval :: a -> Eff (console :: CONSOLE) Unit" , "" , "instance evalShow :: (Show a) => Eval a where" - , " eval = print" + , " eval = logShow" , "" , "instance evalEff :: (Eval a) => Eval (Eff eff a) where" , " eval x = unsafeInterleaveEff x >>= eval" diff --git a/purescript.cabal b/purescript.cabal index 7c8442b04e..2315f56786 100644 --- a/purescript.cabal +++ b/purescript.cabal @@ -28,8 +28,12 @@ extra-source-files: examples/passing/*.purs , tests/support/setup.js , tests/support/package.json , tests/support/prelude/bower.json - , tests/support/prelude/src/*.purs - , tests/support/prelude/src/*.js + , tests/support/prelude/src/Control/*.purs + , tests/support/prelude/src/Control/*.js + , tests/support/prelude/src/Data/*.purs + , tests/support/prelude/src/Data/*.js + , tests/support/prelude/src/Data/Ord/*.purs + , tests/support/prelude/src/Data/Ord/*.js , tests/support/prelude/LICENSE , tests/support/bower.json , tests/support/setup-win.cmd diff --git a/src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs b/src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs index bcc2b395b3..b4b421bd41 100644 --- a/src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs +++ b/src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs @@ -89,16 +89,16 @@ inlineCommonValues = everywhereOnJS convert convert (JSApp ss (JSApp _ (JSApp _ fn [dict]) [x]) [y]) | isDict' semiringInt dict && isFn' fnAdd fn = intOp ss Add x y | isDict' semiringInt dict && isFn' fnMultiply fn = intOp ss Multiply x y - | isDict' moduloSemiringInt dict && isFn' fnDivide fn = intOp ss Divide x y + | isDict' euclideanRingInt dict && isFn' fnDivide fn = intOp ss Divide x y | isDict' ringInt dict && isFn' fnSubtract fn = intOp ss Subtract x y convert other = other fnZero = [(C.prelude, C.zero), (C.dataSemiring, C.zero)] fnOne = [(C.prelude, C.one), (C.dataSemiring, C.one)] fnBottom = [(C.prelude, C.bottom), (C.dataBounded, C.bottom)] fnTop = [(C.prelude, C.top), (C.dataBounded, C.top)] - fnAdd = [(C.prelude, (C.+)), (C.prelude, C.add), (C.dataSemiring, (C.+)), (C.dataSemiring, C.add)] - fnDivide = [(C.prelude, (C./)), (C.prelude, C.div), (C.dataModuloSemiring, C.div)] - fnMultiply = [(C.prelude, (C.*)), (C.prelude, C.mul), (C.dataSemiring, (C.*)), (C.dataSemiring, C.mul)] + fnAdd = [(C.prelude, (C.+)), (C.prelude, (C.add)), (C.dataSemiring, (C.+)), (C.dataSemiring, (C.add))] + fnDivide = [(C.prelude, (C./)), (C.prelude, (C.div)), (C.dataEuclideanRing, C.div)] + fnMultiply = [(C.prelude, (C.*)), (C.prelude, (C.mul)), (C.dataSemiring, (C.*)), (C.dataSemiring, (C.mul))] fnSubtract = [(C.prelude, (C.-)), (C.prelude, C.sub), (C.dataRing, C.sub)] intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0)) @@ -122,8 +122,8 @@ inlineCommonOperators = applyAll $ , binary ringInt opSub Subtract , unary ringInt opNegate Negate - , binary moduloSemiringNumber opDiv Divide - , binary moduloSemiringInt opMod Modulus + , binary euclideanRingNumber opDiv Divide + , binary euclideanRingInt opMod Modulus , binary eqNumber opEq EqualTo , binary eqNumber opNotEq NotEqualTo @@ -159,9 +159,9 @@ inlineCommonOperators = applyAll $ , binary semigroupString opAppend Add - , binary booleanAlgebraBoolean opConj And - , binary booleanAlgebraBoolean opDisj Or - , unary booleanAlgebraBoolean opNot Not + , binary heytingAlgebraBoolean opConj And + , binary heytingAlgebraBoolean opDisj Or + , unary heytingAlgebraBoolean opNot Not , binary' C.dataIntBits (C..|.) BitwiseOr , binary' C.dataIntBits (C..&.) BitwiseAnd @@ -271,11 +271,11 @@ ringNumber = [(C.prelude, C.ringNumber), (C.dataRing, C.ringNumber)] ringInt :: [(String, String)] ringInt = [(C.prelude, C.ringInt), (C.dataRing, C.ringInt)] -moduloSemiringNumber :: [(String, String)] -moduloSemiringNumber = [(C.prelude, C.moduloSemiringNumber), (C.dataModuloSemiring, C.moduloSemiringNumber)] +euclideanRingNumber :: [(String, String)] +euclideanRingNumber = [(C.prelude, C.moduloSemiringNumber), (C.dataEuclideanRing, C.euclideanRingNumber)] -moduloSemiringInt :: [(String, String)] -moduloSemiringInt = [(C.prelude, C.moduloSemiringInt), (C.dataModuloSemiring, C.moduloSemiringInt)] +euclideanRingInt :: [(String, String)] +euclideanRingInt = [(C.prelude, C.moduloSemiringInt), (C.dataEuclideanRing, C.euclideanRingInt)] eqNumber :: [(String, String)] eqNumber = [(C.prelude, C.eqNumber), (C.dataEq, C.eqNumber)] @@ -313,8 +313,8 @@ semigroupString = [(C.prelude, C.semigroupString), (C.dataSemigroup, C.semigroup boundedBoolean :: [(String, String)] boundedBoolean = [(C.prelude, C.boundedBoolean), (C.dataBounded, C.boundedBoolean)] -booleanAlgebraBoolean :: [(String, String)] -booleanAlgebraBoolean = [(C.prelude, C.booleanAlgebraBoolean), (C.dataBooleanAlgebra, C.booleanAlgebraBoolean)] +heytingAlgebraBoolean :: [(String, String)] +heytingAlgebraBoolean = [(C.prelude, C.booleanAlgebraBoolean), (C.dataHeytingAlgebra, C.heytingAlgebraBoolean)] semigroupoidFn :: [(String, String)] semigroupoidFn = [(C.prelude, C.semigroupoidFn), (C.controlSemigroupoid, C.semigroupoidFn)] @@ -353,16 +353,16 @@ opNegate :: [(String, String)] opNegate = [(C.prelude, C.negate), (C.dataRing, C.negate)] opDiv :: [(String, String)] -opDiv = [(C.prelude, (C./)), (C.prelude, C.div), (C.dataModuloSemiring, C.div)] +opDiv = [(C.prelude, (C./)), (C.prelude, C.div), (C.dataEuclideanRing, C.div)] opMod :: [(String, String)] -opMod = [(C.prelude, C.mod), (C.dataModuloSemiring, C.mod)] +opMod = [(C.prelude, C.mod), (C.dataEuclideanRing, C.mod)] opConj :: [(String, String)] -opConj = [(C.prelude, (C.&&)), (C.prelude, C.conj), (C.dataBooleanAlgebra, C.conj)] +opConj = [(C.prelude, (C.&&)), (C.prelude, C.conj), (C.dataHeytingAlgebra, C.conj)] opDisj :: [(String, String)] -opDisj = [(C.prelude, (C.||)), (C.prelude, C.disj), (C.dataBooleanAlgebra, C.disj)] +opDisj = [(C.prelude, (C.||)), (C.prelude, C.disj), (C.dataHeytingAlgebra, C.disj)] opNot :: [(String, String)] -opNot = [(C.prelude, C.not), (C.dataBooleanAlgebra, C.not)] +opNot = [(C.prelude, C.not), (C.dataHeytingAlgebra, C.not)] diff --git a/src/Language/PureScript/Constants.hs b/src/Language/PureScript/Constants.hs index 6a57d3f3ff..15c19c2f78 100644 --- a/src/Language/PureScript/Constants.hs +++ b/src/Language/PureScript/Constants.hs @@ -247,6 +247,12 @@ moduloSemiringNumber = "moduloSemiringNumber" moduloSemiringInt :: String moduloSemiringInt = "moduloSemiringInt" +euclideanRingNumber :: String +euclideanRingNumber = "euclideanRingNumber" + +euclideanRingInt :: String +euclideanRingInt = "euclideanRingInt" + ordBoolean :: String ordBoolean = "ordBoolean" @@ -283,6 +289,9 @@ boundedBoolean = "boundedBoolean" booleanAlgebraBoolean :: String booleanAlgebraBoolean = "booleanAlgebraBoolean" +heytingAlgebraBoolean :: String +heytingAlgebraBoolean = "heytingAlgebraBoolean" + semigroupString :: String semigroupString = "semigroupString" @@ -348,11 +357,8 @@ dataBounded = "Data_Bounded" dataSemigroup :: String dataSemigroup = "Data_Semigroup" -dataModuloSemiring :: String -dataModuloSemiring = "Data_ModuloSemiring" - -dataBooleanAlgebra :: String -dataBooleanAlgebra = "Data_BooleanAlgebra" +dataHeytingAlgebra :: String +dataHeytingAlgebra = "Data_HeytingAlgebra" dataEq :: String dataEq = "Data_Eq" @@ -366,6 +372,9 @@ dataSemiring = "Data_Semiring" dataRing :: String dataRing = "Data_Ring" +dataEuclideanRing :: String +dataEuclideanRing = "Data_EuclideanRing" + dataFunction :: String dataFunction = "Data_Function" diff --git a/src/Language/PureScript/Sugar/TypeClasses/Deriving.hs b/src/Language/PureScript/Sugar/TypeClasses/Deriving.hs index f788d485fc..0a01733734 100755 --- a/src/Language/PureScript/Sugar/TypeClasses/Deriving.hs +++ b/src/Language/PureScript/Sugar/TypeClasses/Deriving.hs @@ -50,11 +50,11 @@ deriveInstance mn ds (TypeInstanceDeclaration nm deps className tys@[ty] Derived , Just (Qualified mn' tyCon, args) <- unwrapTypeConstructor ty , mn == fromMaybe mn mn' = TypeInstanceDeclaration nm deps className tys . ExplicitInstance <$> deriveGeneric mn ds tyCon args - | className == Qualified (Just (ModuleName [ ProperName "Prelude" ])) (ProperName "Eq") + | className == Qualified (Just (ModuleName [ ProperName "Data", ProperName "Eq" ])) (ProperName "Eq") , Just (Qualified mn' tyCon, _) <- unwrapTypeConstructor ty , mn == fromMaybe mn mn' = TypeInstanceDeclaration nm deps className tys . ExplicitInstance <$> deriveEq mn ds tyCon - | className == Qualified (Just (ModuleName [ ProperName "Prelude" ])) (ProperName "Ord") + | className == Qualified (Just (ModuleName [ ProperName "Data", ProperName "Ord" ])) (ProperName "Ord") , Just (Qualified mn' tyCon, _) <- unwrapTypeConstructor ty , mn == fromMaybe mn mn' = TypeInstanceDeclaration nm deps className tys . ExplicitInstance <$> deriveOrd mn ds tyCon @@ -218,8 +218,8 @@ deriveGeneric mn ds tyConNm dargs = do = App (lamCase (Ident "r") [ mkRecCase (decomposeRec rec) , CaseAlternative [NullBinder] (Right mkNothing) ]) - (App e (mkPrelVar (Ident "unit"))) - fromSpineFun e _ = App (mkGenVar (Ident C.fromSpine)) (App e (mkPrelVar (Ident "unit"))) + (App e unitVal) + fromSpineFun e _ = App (mkGenVar (Ident C.fromSpine)) (App e unitVal) mkRecCase :: [(String, Type)] -> CaseAlternative mkRecCase rs = @@ -237,10 +237,13 @@ deriveGeneric mn ds tyConNm dargs = do -- Helpers liftApplicative :: Expr -> [Expr] -> Expr - liftApplicative = foldl' (\x e -> App (App (mkPrelVar (Ident "apply")) x) e) + liftApplicative = foldl' (\x e -> App (App applyFn x) e) - mkPrelVar :: Ident -> Expr - mkPrelVar = mkVarMn (Just (ModuleName [ProperName C.prelude])) + unitVal :: Expr + unitVal = mkVarMn (Just (ModuleName [ProperName "Data", ProperName "Unit"])) (Ident "unit") + + applyFn :: Expr + applyFn = mkVarMn (Just (ModuleName [ProperName "Control", ProperName "Apply"])) (Ident "apply") mkGenVar :: Ident -> Expr mkGenVar = mkVarMn (Just (ModuleName [ProperName "Data", ProperName C.generic])) @@ -265,10 +268,10 @@ deriveEq mn ds tyConNm = do mkEqFunction _ = internalError "mkEqFunction: expected DataDeclaration" preludeConj :: Expr -> Expr -> Expr - preludeConj = App . App (Var (Qualified (Just (ModuleName [ProperName C.prelude])) (Ident C.conj))) + preludeConj = App . App (Var (Qualified (Just (ModuleName [ProperName "Data", ProperName "HeytingAlgebra"])) (Ident C.conj))) preludeEq :: Expr -> Expr -> Expr - preludeEq = App . App (Var (Qualified (Just (ModuleName [ProperName C.prelude])) (Ident C.eq))) + preludeEq = App . App (Var (Qualified (Just (ModuleName [ProperName "Data", ProperName "Eq"])) (Ident C.eq))) addCatch :: [CaseAlternative] -> [CaseAlternative] addCatch xs @@ -326,13 +329,19 @@ deriveOrd mn ds tyConNm = do | null xs = [catchAll] -- No type constructors | otherwise = xs where - catchAll = CaseAlternative [NullBinder, NullBinder] (Right (preludeCtor "EQ")) + catchAll = CaseAlternative [NullBinder, NullBinder] (Right (orderingCtor "EQ")) + + orderingName :: String -> Qualified (ProperName a) + orderingName = Qualified (Just (ModuleName [ProperName "Data", ProperName "Ordering"])) . ProperName + + orderingCtor :: String -> Expr + orderingCtor = Constructor . orderingName - preludeCtor :: String -> Expr - preludeCtor = Constructor . Qualified (Just (ModuleName [ProperName C.prelude])) . ProperName + orderingBinder :: String -> Binder + orderingBinder name = ConstructorBinder (orderingName name) [] - preludeCompare :: Expr -> Expr -> Expr - preludeCompare = App . App (Var (Qualified (Just (ModuleName [ProperName C.prelude])) (Ident C.compare))) + ordCompare :: Expr -> Expr -> Expr + ordCompare = App . App (Var (Qualified (Just (ModuleName [ProperName "Data", ProperName "Ord"])) (Ident C.compare))) mkCtorClauses :: ((ProperName 'ConstructorName, [Type]), Bool) -> m [CaseAlternative] mkCtorClauses ((ctorName, tys), isLast) = do @@ -342,11 +351,11 @@ deriveOrd mn ds tyConNm = do extras | not isLast = [ CaseAlternative [ ConstructorBinder (Qualified (Just mn) ctorName) (replicate (length tys) NullBinder) , NullBinder ] - (Right (preludeCtor "LT")) + (Right (orderingCtor "LT")) , CaseAlternative [ NullBinder , ConstructorBinder (Qualified (Just mn) ctorName) (replicate (length tys) NullBinder) ] - (Right (preludeCtor "GT")) + (Right (orderingCtor "GT")) ] | otherwise = [] return $ CaseAlternative [ caseBinder identsL @@ -359,12 +368,12 @@ deriveOrd mn ds tyConNm = do caseBinder idents = ConstructorBinder (Qualified (Just mn) ctorName) (map VarBinder idents) appendAll :: [Expr] -> Expr - appendAll [] = preludeCtor "EQ" + appendAll [] = orderingCtor "EQ" appendAll [x] = x - appendAll (x : xs) = Case [x] [ CaseAlternative [ ConstructorBinder (Qualified (Just (ModuleName [ProperName C.prelude])) (ProperName "LT")) [] ] - (Right (preludeCtor "LT")) - , CaseAlternative [ ConstructorBinder (Qualified (Just (ModuleName [ProperName C.prelude])) (ProperName "GT")) [] ] - (Right (preludeCtor "GT")) + appendAll (x : xs) = Case [x] [ CaseAlternative [orderingBinder "LT"] + (Right (orderingCtor "LT")) + , CaseAlternative [orderingBinder "GT"] + (Right (orderingCtor "GT")) , CaseAlternative [ NullBinder ] (Right (appendAll xs)) ] @@ -374,7 +383,7 @@ deriveOrd mn ds tyConNm = do appendAll . map (\(str, typ) -> toOrdering (Accessor str l) (Accessor str r) typ) $ decomposeRec rec - toOrdering l r _ = preludeCompare l r + toOrdering l r _ = ordCompare l r findTypeDecl :: (MonadError MultipleErrors m) diff --git a/tests/Main.hs b/tests/Main.hs index 152cd44e56..0e605b3252 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -1,16 +1,3 @@ ------------------------------------------------------------------------------ --- --- Module : Main --- License : MIT (http://opensource.org/licenses/MIT) --- --- Maintainer : Phil Freeman --- Stability : experimental --- Portability : --- --- | --- ------------------------------------------------------------------------------ - {-# LANGUAGE DataKinds #-} {-# LANGUAGE DoAndIfThenElse #-} {-# LANGUAGE TupleSections #-} diff --git a/tests/TestPsci.hs b/tests/TestPsci.hs index 3d058df020..a3c08008ab 100644 --- a/tests/TestPsci.hs +++ b/tests/TestPsci.hs @@ -75,7 +75,7 @@ completionTestData = , (":show a", []) -- :type should complete values and data constructors in scope - , (":type Control.Monad.Eff.Console.lo", [":type Control.Monad.Eff.Console.log"]) + , (":type Control.Monad.Eff.Console.lo", [":type Control.Monad.Eff.Console.log", ":type Control.Monad.Eff.Console.logShow"]) , (":type uni", [":type unit"]) , (":type E", [":type EQ"]) @@ -102,7 +102,7 @@ completionTestData = , ("uni", ["unit"]) , ("Control.Monad.Eff.Class.", ["Control.Monad.Eff.Class.liftEff"]) , ("G", ["GT"]) - , ("Prelude.L", ["Prelude.LT"]) + , ("Data.Ordering.L", ["Data.Ordering.LT"]) -- if a module is imported qualified, values should complete under the -- qualified name, as well as the original name. @@ -148,12 +148,37 @@ controlMonadSTasST = (s "Control.Monad.ST", P.Implicit, Just (s "ST")) supportModules :: [String] supportModules = - [ "Control.Monad.Eff.Class" - , "Control.Monad.Eff.Console" + [ "Control.Applicative" + , "Control.Apply" + , "Control.Bind" + , "Control.Category" + , "Control.Monad" , "Control.Monad.Eff" + , "Control.Monad.Eff.Class" + , "Control.Monad.Eff.Console" , "Control.Monad.Eff.Unsafe" , "Control.Monad.ST" + , "Control.Semigroupoid" + , "Data.Boolean" + , "Data.BooleanAlgebra" + , "Data.Bounded" + , "Data.CommutativeRing" + , "Data.Eq" + , "Data.EuclideanRing" + , "Data.Field" , "Data.Function" + , "Data.Function.Uncurried" + , "Data.Functor" + , "Data.HeytingAlgebra" + , "Data.Ord" + , "Data.Ord.Unsafe" + , "Data.Ordering" + , "Data.Ring" + , "Data.Semigroup" + , "Data.Semiring" + , "Data.Show" + , "Data.Unit" + , "Data.Void" , "Prelude" , "Test.Assert" ] diff --git a/tests/support/bower.json b/tests/support/bower.json index c29e6e82bc..5aaaf5e3e9 100644 --- a/tests/support/bower.json +++ b/tests/support/bower.json @@ -1,11 +1,11 @@ { "name": "purescript-test-suite-support", "dependencies": { - "purescript-eff": "0.1.0", - "purescript-prelude": "0.1.3", - "purescript-assert": "0.1.1", - "purescript-st": "0.1.0", - "purescript-console": "0.1.0", - "purescript-functions": "0.1.0" + "purescript-assert": "^1.0.0-rc.1", + "purescript-console": "^1.0.0-rc.1", + "purescript-eff": "^1.0.0-rc.1", + "purescript-functions": "^1.0.0-rc.1", + "purescript-prelude": "^1.0.0-rc.1", + "purescript-st": "^1.0.0-rc.1" } } diff --git a/tests/support/flattened/Control-Applicative.purs b/tests/support/flattened/Control-Applicative.purs new file mode 100644 index 0000000000..34cb6d8b36 --- /dev/null +++ b/tests/support/flattened/Control-Applicative.purs @@ -0,0 +1,64 @@ +module Control.Applicative + ( class Applicative, pure + , liftA1 + , unless, when + , module Control.Apply + , module Data.Functor + ) where + +import Control.Apply (class Apply, apply, (*>), (<*), (<*>)) + +import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>)) +import Data.Unit (Unit, unit) + +-- | The `Applicative` type class extends the [`Apply`](#apply) type class +-- | with a `pure` function, which can be used to create values of type `f a` +-- | from values of type `a`. +-- | +-- | Where [`Apply`](#apply) provides the ability to lift functions of two or +-- | more arguments to functions whose arguments are wrapped using `f`, and +-- | [`Functor`](#functor) provides the ability to lift functions of one +-- | argument, `pure` can be seen as the function which lifts functions of +-- | _zero_ arguments. That is, `Applicative` functors support a lifting +-- | operation for any number of function arguments. +-- | +-- | Instances must satisfy the following laws in addition to the `Apply` +-- | laws: +-- | +-- | - Identity: `(pure id) <*> v = v` +-- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)` +-- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)` +-- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u` +class Apply f <= Applicative f where + pure :: forall a. a -> f a + +instance applicativeFn :: Applicative ((->) r) where + pure x _ = x + +instance applicativeArray :: Applicative Array where + pure x = [x] + +-- | `liftA1` provides a default implementation of `(<$>)` for any +-- | [`Applicative`](#applicative) functor, without using `(<$>)` as provided +-- | by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass +-- | relationship. +-- | +-- | `liftA1` can therefore be used to write [`Functor`](#functor) instances +-- | as follows: +-- | +-- | ```purescript +-- | instance functorF :: Functor F where +-- | map = liftA1 +-- | ``` +liftA1 :: forall f a b. Applicative f => (a -> b) -> f a -> f b +liftA1 f a = pure f <*> a + +-- | Perform a applicative action when a condition is true. +when :: forall m. Applicative m => Boolean -> m Unit -> m Unit +when true m = m +when false _ = pure unit + +-- | Perform a applicative action unless a condition is true. +unless :: forall m. Applicative m => Boolean -> m Unit -> m Unit +unless false m = m +unless true _ = pure unit diff --git a/tests/support/flattened/Control-Apply.js b/tests/support/flattened/Control-Apply.js new file mode 100644 index 0000000000..16a351a46b --- /dev/null +++ b/tests/support/flattened/Control-Apply.js @@ -0,0 +1,16 @@ +"use strict"; + +// module Control.Apply + +exports.arrayApply = function (fs) { + return function (xs) { + var result = []; + var n = 0; + for (var i = 0, l = fs.length; i < l; i++) { + for (var j = 0, k = xs.length; j < k; j++) { + result[n++] = fs[i](xs[j]); + } + } + return result; + }; +}; diff --git a/tests/support/flattened/Control-Apply.purs b/tests/support/flattened/Control-Apply.purs new file mode 100644 index 0000000000..e6e7e1d867 --- /dev/null +++ b/tests/support/flattened/Control-Apply.purs @@ -0,0 +1,78 @@ +module Control.Apply + ( class Apply, apply, (<*>) + , applyFirst, (<*) + , applySecond, (*>) + , lift2, lift3, lift4, lift5 + , module Data.Functor + ) where + +import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>)) +import Data.Function (const) +import Control.Category (id) + +-- | The `Apply` class provides the `(<*>)` which is used to apply a function +-- | to an argument under a type constructor. +-- | +-- | `Apply` can be used to lift functions of two or more arguments to work on +-- | values wrapped with the type constructor `f`. It might also be understood +-- | in terms of the `lift2` function: +-- | +-- | ```purescript +-- | lift2 :: forall f a b c. Apply f => (a -> b -> c) -> f a -> f b -> f c +-- | lift2 f a b = f <$> a <*> b +-- | ``` +-- | +-- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts +-- | the function application operator `($)` to arguments wrapped with the +-- | type constructor `f`. +-- | +-- | Instances must satisfy the following law in addition to the `Functor` +-- | laws: +-- | +-- | - Associative composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)` +-- | +-- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor. +class Functor f <= Apply f where + apply :: forall a b. f (a -> b) -> f a -> f b + +infixl 4 apply as <*> + +instance applyFn :: Apply ((->) r) where + apply f g x = f x (g x) + +instance applyArray :: Apply Array where + apply = arrayApply + +foreign import arrayApply :: forall a b. Array (a -> b) -> Array a -> Array b + +-- | Combine two effectful actions, keeping only the result of the first. +applyFirst :: forall a b f. Apply f => f a -> f b -> f a +applyFirst a b = const <$> a <*> b + +infixl 4 applyFirst as <* + +-- | Combine two effectful actions, keeping only the result of the second. +applySecond :: forall a b f. Apply f => f a -> f b -> f b +applySecond a b = const id <$> a <*> b + +infixl 4 applySecond as *> + +-- | Lift a function of two arguments to a function which accepts and returns +-- | values wrapped with the type constructor `f`. +lift2 :: forall a b c f. Apply f => (a -> b -> c) -> f a -> f b -> f c +lift2 f a b = f <$> a <*> b + +-- | Lift a function of three arguments to a function which accepts and returns +-- | values wrapped with the type constructor `f`. +lift3 :: forall a b c d f. Apply f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d +lift3 f a b c = f <$> a <*> b <*> c + +-- | Lift a function of four arguments to a function which accepts and returns +-- | values wrapped with the type constructor `f`. +lift4 :: forall a b c d e f. Apply f => (a -> b -> c -> d -> e) -> f a -> f b -> f c -> f d -> f e +lift4 f a b c d = f <$> a <*> b <*> c <*> d + +-- | Lift a function of five arguments to a function which accepts and returns +-- | values wrapped with the type constructor `f`. +lift5 :: forall a b c d e f g. Apply f => (a -> b -> c -> d -> e -> g) -> f a -> f b -> f c -> f d -> f e -> f g +lift5 f a b c d e = f <$> a <*> b <*> c <*> d <*> e diff --git a/tests/support/flattened/Control-Bind.js b/tests/support/flattened/Control-Bind.js new file mode 100644 index 0000000000..d0e09d4f5d --- /dev/null +++ b/tests/support/flattened/Control-Bind.js @@ -0,0 +1,13 @@ +"use strict"; + +// module Control.Bind + +exports.arrayBind = function (arr) { + return function (f) { + var result = []; + for (var i = 0, l = arr.length; i < l; i++) { + Array.prototype.push.apply(result, f(arr[i])); + } + return result; + }; +}; diff --git a/tests/support/flattened/Control-Bind.purs b/tests/support/flattened/Control-Bind.purs new file mode 100644 index 0000000000..1b045aa9ef --- /dev/null +++ b/tests/support/flattened/Control-Bind.purs @@ -0,0 +1,103 @@ +module Control.Bind + ( class Bind, bind, (>>=) + , bindFlipped, (=<<) + , join + , composeKleisli, (>=>) + , composeKleisliFlipped, (<=<) + , ifM + , module Data.Functor + , module Control.Apply + , module Control.Applicative + ) where + +import Control.Applicative (class Applicative, liftA1, pure, unless, when) +import Control.Apply (class Apply, apply, (*>), (<*), (<*>)) +import Control.Category (id) + +import Data.Function (flip) +import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>)) + +-- | The `Bind` type class extends the [`Apply`](#apply) type class with a +-- | "bind" operation `(>>=)` which composes computations in sequence, using +-- | the return value of one computation to determine the next computation. +-- | +-- | The `>>=` operator can also be expressed using `do` notation, as follows: +-- | +-- | ```purescript +-- | x >>= f = do y <- x +-- | f y +-- | ``` +-- | +-- | where the function argument of `f` is given the name `y`. +-- | +-- | Instances must satisfy the following law in addition to the `Apply` +-- | laws: +-- | +-- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)` +-- | +-- | Associativity tells us that we can regroup operations which use `do` +-- | notation so that we can unambiguously write, for example: +-- | +-- | ```purescript +-- | do x <- m1 +-- | y <- m2 x +-- | m3 x y +-- | ``` +class Apply m <= Bind m where + bind :: forall a b. m a -> (a -> m b) -> m b + +infixl 1 bind as >>= + +-- | `bindFlipped` is `bind` with its arguments reversed. For example: +-- | +-- | ```purescript +-- | print =<< random +-- | ``` +bindFlipped :: forall m a b. Bind m => (a -> m b) -> m a -> m b +bindFlipped = flip bind + +infixl 1 bindFlipped as =<< + +instance bindFn :: Bind ((->) r) where + bind m f x = f (m x) x + +instance bindArray :: Bind Array where + bind = arrayBind + +foreign import arrayBind :: forall a b. Array a -> (a -> Array b) -> Array b + +-- | Collapse two applications of a monadic type constructor into one. +join :: forall a m. Bind m => m (m a) -> m a +join m = m >>= id + +-- | Forwards Kleisli composition. +-- | +-- | For example: +-- | +-- | ```purescript +-- | import Data.Array (head, tail) +-- | +-- | third = tail >=> tail >=> head +-- | ``` +composeKleisli :: forall a b c m. Bind m => (a -> m b) -> (b -> m c) -> a -> m c +composeKleisli f g a = f a >>= g + +infixr 1 composeKleisli as >=> + +-- | Backwards Kleisli composition. +composeKleisliFlipped :: forall a b c m. Bind m => (b -> m c) -> (a -> m b) -> a -> m c +composeKleisliFlipped f g a = f =<< g a + +infixr 1 composeKleisliFlipped as <=< + +-- | Execute a monadic action if a condition holds. +-- | +-- | For example: +-- | +-- | ```purescript +-- | main = ifM ((< 0.5) <$> random) +-- | (trace "Heads") +-- | (trace "Tails") +-- | ``` +ifM :: forall a m. Bind m => m Boolean -> m a -> m a -> m a +ifM cond t f = cond >>= \cond' -> if cond' then t else f diff --git a/tests/support/flattened/Control-Category.purs b/tests/support/flattened/Control-Category.purs new file mode 100644 index 0000000000..9fa17b2353 --- /dev/null +++ b/tests/support/flattened/Control-Category.purs @@ -0,0 +1,20 @@ +module Control.Category + ( class Category, id + , module Control.Semigroupoid + ) where + +import Control.Semigroupoid (class Semigroupoid, compose, (<<<), (>>>)) + +-- | `Category`s consist of objects and composable morphisms between them, and +-- | as such are [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids` +-- | must have an identity element. +-- | +-- | Instances must satisfy the following law in addition to the +-- | `Semigroupoid` law: +-- | +-- | - Identity: `id <<< p = p <<< id = p` +class Semigroupoid a <= Category a where + id :: forall t. a t t + +instance categoryFn :: Category (->) where + id x = x diff --git a/tests/support/flattened/Control-Monad-Eff-Class.purs b/tests/support/flattened/Control-Monad-Eff-Class.purs index dbfd58ebcf..6c55965acb 100644 --- a/tests/support/flattened/Control-Monad-Eff-Class.purs +++ b/tests/support/flattened/Control-Monad-Eff-Class.purs @@ -1,23 +1,22 @@ -module Control.Monad.Eff.Class - ( MonadEff - , liftEff - ) where +module Control.Monad.Eff.Class where -import Prelude - -import Control.Monad.Eff +import Control.Category (id) +import Control.Monad (class Monad) +import Control.Monad.Eff (Eff) -- | The `MonadEff` class captures those monads which support native effects. -- | --- | Instances are provided for `Eff` itself, and the standard monad transformers. +-- | Instances are provided for `Eff` itself, and the standard monad +-- | transformers. -- | --- | `liftEff` can be used in any appropriate monad transformer stack to lift an action --- | of type `Eff eff a` into the monad. +-- | `liftEff` can be used in any appropriate monad transformer stack to lift an +-- | action of type `Eff eff a` into the monad. -- | --- | Note that `MonadEff` is parameterized by the row of effects, so type inference can be --- | tricky. It is generally recommended to either work with a polymorphic row of effects, --- | or a concrete, closed row of effects such as `(trace :: Trace)`. -class (Monad m) <= MonadEff eff m where +-- | Note that `MonadEff` is parameterized by the row of effects, so type +-- | inference can be tricky. It is generally recommended to either work with a +-- | polymorphic row of effects, or a concrete, closed row of effects such as +-- | `(trace :: Trace)`. +class Monad m <= MonadEff eff m where liftEff :: forall a. Eff eff a -> m a instance monadEffEff :: MonadEff eff (Eff eff) where diff --git a/tests/support/flattened/Control-Monad-Eff-Console.js b/tests/support/flattened/Control-Monad-Eff-Console.js index 9ccfc26b45..606c4d9b94 100644 --- a/tests/support/flattened/Control-Monad-Eff-Console.js +++ b/tests/support/flattened/Control-Monad-Eff-Console.js @@ -1,4 +1,3 @@ -/* global exports, console */ "use strict"; // module Control.Monad.Eff.Console @@ -10,9 +9,23 @@ exports.log = function (s) { }; }; +exports.warn = function (s) { + return function () { + console.warn(s); + return {}; + }; +}; + exports.error = function (s) { return function () { console.error(s); return {}; }; }; + +exports.info = function (s) { + return function () { + console.info(s); + return {}; + }; +}; diff --git a/tests/support/flattened/Control-Monad-Eff-Console.purs b/tests/support/flattened/Control-Monad-Eff-Console.purs index 0a03ee4d3e..211baf031e 100644 --- a/tests/support/flattened/Control-Monad-Eff-Console.purs +++ b/tests/support/flattened/Control-Monad-Eff-Console.purs @@ -1,18 +1,54 @@ module Control.Monad.Eff.Console where -import Prelude +import Control.Monad.Eff (Eff) -import Control.Monad.Eff +import Data.Show (class Show, show) +import Data.Unit (Unit) --- | The `CONSOLE` effect represents those computations which write to the console. +-- | The `CONSOLE` effect represents those computations which write to the +-- | console. foreign import data CONSOLE :: ! -- | Write a message to the console. -foreign import log :: forall eff. String -> Eff (console :: CONSOLE | eff) Unit +foreign import log + :: forall eff + . String + -> Eff (console :: CONSOLE | eff) Unit + +-- | Write a value to the console, using its `Show` instance to produce a +-- | `String`. +logShow :: forall a eff. Show a => a -> Eff (console :: CONSOLE | eff) Unit +logShow a = log (show a) + +-- | Write an warning to the console. +foreign import warn + :: forall eff + . String + -> Eff (console :: CONSOLE | eff) Unit + +-- | Write an warning value to the console, using its `Show` instance to produce +-- | a `String`. +warnShow :: forall a eff. Show a => a -> Eff (console :: CONSOLE | eff) Unit +warnShow a = warn (show a) -- | Write an error to the console. -foreign import error :: forall eff. String -> Eff (console :: CONSOLE | eff) Unit +foreign import error + :: forall eff + . String + -> Eff (console :: CONSOLE | eff) Unit + +-- | Write an error value to the console, using its `Show` instance to produce a +-- | `String`. +errorShow :: forall a eff. Show a => a -> Eff (console :: CONSOLE | eff) Unit +errorShow a = error (show a) + +-- | Write an info message to the console. +foreign import info + :: forall eff + . String + -> Eff (console :: CONSOLE | eff) Unit --- | Write a value to the console, using its `Show` instance to produce a `String`. -print :: forall a eff. (Show a) => a -> Eff (console :: CONSOLE | eff) Unit -print = log <<< show +-- | Write an info value to the console, using its `Show` instance to produce a +-- | `String`. +infoShow :: forall a eff. Show a => a -> Eff (console :: CONSOLE | eff) Unit +infoShow a = info (show a) diff --git a/tests/support/flattened/Control-Monad-Eff-Unsafe.js b/tests/support/flattened/Control-Monad-Eff-Unsafe.js index bada18a47e..b24421fb08 100644 --- a/tests/support/flattened/Control-Monad-Eff-Unsafe.js +++ b/tests/support/flattened/Control-Monad-Eff-Unsafe.js @@ -1,4 +1,3 @@ -/* global exports */ "use strict"; // module Control.Monad.Eff.Unsafe diff --git a/tests/support/flattened/Control-Monad-Eff-Unsafe.purs b/tests/support/flattened/Control-Monad-Eff-Unsafe.purs index 5d6f104483..3edb6d2400 100644 --- a/tests/support/flattened/Control-Monad-Eff-Unsafe.purs +++ b/tests/support/flattened/Control-Monad-Eff-Unsafe.purs @@ -1,10 +1,19 @@ module Control.Monad.Eff.Unsafe where -import Prelude +import Control.Monad.Eff (Eff, runPure) +import Control.Semigroupoid ((<<<)) -import Control.Monad.Eff +-- | Change the type of an effectful computation, allowing it to be run in +-- | another context. +-- | +-- | *Note*: use of this function can result in arbitrary side-effects. +foreign import unsafeInterleaveEff + :: forall eff1 eff2 a + . Eff eff1 a + -> Eff eff2 a --- | Change the type of an effectful computation, allowing it to be run in another context. +-- | Run an effectful computation. -- | --- | Note: use of this function can result in arbitrary side-effects. -foreign import unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a +-- | *Note*: use of this function can result in arbitrary side-effects. +unsafePerformEff :: forall eff a. Eff eff a -> a +unsafePerformEff = runPure <<< unsafeInterleaveEff diff --git a/tests/support/flattened/Control-Monad-Eff.js b/tests/support/flattened/Control-Monad-Eff.js index 1498f2139d..af32693439 100644 --- a/tests/support/flattened/Control-Monad-Eff.js +++ b/tests/support/flattened/Control-Monad-Eff.js @@ -1,9 +1,8 @@ -/* global exports */ "use strict"; // module Control.Monad.Eff -exports.returnE = function (a) { +exports.pureE = function (a) { return function () { return a; }; diff --git a/tests/support/flattened/Control-Monad-Eff.purs b/tests/support/flattened/Control-Monad-Eff.purs index 0417c198b7..425407e732 100644 --- a/tests/support/flattened/Control-Monad-Eff.purs +++ b/tests/support/flattened/Control-Monad-Eff.purs @@ -1,34 +1,28 @@ module Control.Monad.Eff - ( Eff() - , Pure() + ( Eff + , Pure , runPure , untilE, whileE, forE, foreachE ) where -import Prelude +import Control.Applicative (class Applicative, liftA1) +import Control.Apply (class Apply) +import Control.Bind (class Bind) +import Control.Monad (class Monad, ap) + +import Data.Functor (class Functor) +import Data.Unit (Unit) -- | The `Eff` type constructor is used to represent _native_ effects. -- | --- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details. +-- | See [Handling Native Effects with the Eff Monad](http://www.purescript.org/learn/eff/) +-- | for more details. -- | --- | 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. +-- | 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. foreign import data Eff :: # ! -> * -> * -foreign import returnE :: forall e a. a -> Eff e a - -foreign import bindE :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b - --- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled. --- | --- | The `runPure` function can be used to run pure computations and obtain their result. -type Pure a = forall e. Eff e a - --- | Run a pure computation and return its result. --- | --- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach --- | is to use parentheses instead. -foreign import runPure :: forall a. Pure a -> a - instance functorEff :: Functor (Eff e) where map = liftA1 @@ -36,32 +30,48 @@ instance applyEff :: Apply (Eff e) where apply = ap instance applicativeEff :: Applicative (Eff e) where - pure = returnE + pure = pureE + +foreign import pureE :: forall e a. a -> Eff e a instance bindEff :: Bind (Eff e) where bind = bindE +foreign import bindE :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b + instance monadEff :: Monad (Eff e) +-- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which +-- | all effects have been handled. +-- | +-- | The `runPure` function can be used to run pure computations and obtain +-- | their result. +type Pure a = Eff () a + +-- | Run a pure computation and return its result. +foreign import runPure :: forall a. Pure a -> a + -- | Loop until a condition becomes `true`. -- | --- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`, --- | until its return value is `true`. +-- | `untilE b` is an effectful computation which repeatedly runs the effectful +-- | computation `b`, until its return value is `true`. foreign import untilE :: forall e. Eff e Boolean -> Eff e Unit -- | Loop while a condition is `true`. -- | --- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is --- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends. +-- | `whileE b m` is effectful computation which runs the effectful computation +-- | `b`. If its result is `true`, it runs the effectful computation `m` and +-- | loops. If not, the computation ends. foreign import whileE :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit -- | Loop over a consecutive collection of numbers. -- | --- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs --- | between `lo` (inclusive) and `hi` (exclusive). -foreign import forE :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit +-- | `forE lo hi f` runs the computation returned by the function `f` for each +-- | of the inputs between `lo` (inclusive) and `hi` (exclusive). +foreign import forE :: forall e. Int -> Int -> (Int -> Eff e Unit) -> Eff e Unit -- | Loop over an array of values. -- | --- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`. +-- | `foreach xs f` runs the computation returned by the function `f` for each +-- | of the inputs `xs`. foreign import foreachE :: forall e a. Array a -> (a -> Eff e Unit) -> Eff e Unit diff --git a/tests/support/flattened/Control-Monad-ST.purs b/tests/support/flattened/Control-Monad-ST.purs index ac113e58a0..78fec979de 100644 --- a/tests/support/flattened/Control-Monad-ST.purs +++ b/tests/support/flattened/Control-Monad-ST.purs @@ -1,42 +1,64 @@ module Control.Monad.ST where -import Prelude - import Control.Monad.Eff (Eff(), runPure) --- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation. +-- | The `ST` effect represents _local mutation_, i.e. mutation which does not +-- | "escape" into the surrounding computation. -- | --- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access. +-- | An `ST` computation is parameterized by a phantom type which is used to +-- | restrict the set of reference cells it is allowed to access. -- | -- | The `runST` function can be used to handle the `ST` effect. foreign import data ST :: * -> ! --- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect. +-- | The type `STRef s a` represents a mutable reference holding a value of +-- | type `a`, which can be used with the `ST s` effect. foreign import data STRef :: * -> * -> * -- | Create a new mutable reference. -foreign import newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a) +foreign import newSTRef + :: forall a h r + . a + -> Eff (st :: ST h | r) (STRef h a) -- | Read the current value of a mutable reference. -foreign import readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a +foreign import readSTRef + :: forall a h r + . STRef h a + -> Eff (st :: ST h | r) a --- | Modify the value of a mutable reference by applying a function to the current value. -foreign import modifySTRef :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a +-- | Modify the value of a mutable reference by applying a function to the +-- | current value. +foreign import modifySTRef + :: forall a h r + . STRef h a -> (a -> a) + -> Eff (st :: ST h | r) a -- | Set the value of a mutable reference. -foreign import writeSTRef :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a +foreign import writeSTRef + :: forall a h r + . STRef h a + -> a + -> Eff (st :: ST h | r) a -- | Run an `ST` computation. -- | --- | 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 +-- | 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 -- | to the surrounding computation. -- | --- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead. -foreign import runST :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a +-- | It may cause problems to apply this function using the `$` operator. The +-- | recommended approach is to use parentheses instead. +foreign import runST + :: forall a r + . (forall h. Eff (st :: ST h | r) a) + -> Eff r a --- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`. +-- | A convenience function which combines `runST` with `runPure`, which can be +-- | used when the only required effect is `ST`. -- | --- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach --- | is to use parentheses instead. -pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a +-- | Note: since this function has a rank-2 type, it may cause problems to apply +-- | this function using the `$` operator. The recommended approach is to use +-- | parentheses instead. +pureST :: forall a. (forall h. Eff (st :: ST h) a) -> a pureST st = runPure (runST st) diff --git a/tests/support/flattened/Control-Monad.purs b/tests/support/flattened/Control-Monad.purs new file mode 100644 index 0000000000..b548721d61 --- /dev/null +++ b/tests/support/flattened/Control-Monad.purs @@ -0,0 +1,63 @@ +module Control.Monad + ( class Monad + , liftM1 + , ap + , module Data.Functor + , module Control.Apply + , module Control.Applicative + , module Control.Bind + ) where + +import Control.Applicative (class Applicative, liftA1, pure, unless, when) +import Control.Apply (class Apply, apply, (*>), (<*), (<*>)) +import Control.Bind (class Bind, bind, ifM, join, (<=<), (=<<), (>=>), (>>=)) + +import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>)) + +-- | The `Monad` type class combines the operations of the `Bind` and +-- | `Applicative` type classes. Therefore, `Monad` instances represent type +-- | constructors which support sequential composition, and also lifting of +-- | functions of arbitrary arity. +-- | +-- | Instances must satisfy the following laws in addition to the +-- | `Applicative` and `Bind` laws: +-- | +-- | - Left Identity: `pure x >>= f = f x` +-- | - Right Identity: `x >>= pure = x` +class (Applicative m, Bind m) <= Monad m + +instance monadFn :: Monad ((->) r) +instance monadArray :: Monad Array + +-- | `liftM1` provides a default implementation of `(<$>)` for any +-- | [`Monad`](#monad), without using `(<$>)` as provided by the +-- | [`Functor`](#functor)-[`Monad`](#monad) superclass relationship. +-- | +-- | `liftM1` can therefore be used to write [`Functor`](#functor) instances +-- | as follows: +-- | +-- | ```purescript +-- | instance functorF :: Functor F where +-- | map = liftM1 +-- | ``` +liftM1 :: forall m a b. Monad m => (a -> b) -> m a -> m b +liftM1 f a = do + a' <- a + pure (f a') + +-- | `ap` provides a default implementation of `(<*>)` for any +-- | [`Monad`](#monad), without using `(<*>)` as provided by the +-- | [`Apply`](#apply)-[`Monad`](#monad) superclass relationship. +-- | +-- | `ap` can therefore be used to write [`Apply`](#apply) instances as +-- | follows: +-- | +-- | ```purescript +-- | instance applyF :: Apply F where +-- | apply = ap +-- | ``` +ap :: forall m a b. Monad m => m (a -> b) -> m a -> m b +ap f a = do + f' <- f + a' <- a + pure (f' a') diff --git a/tests/support/flattened/Control-Semigroupoid.purs b/tests/support/flattened/Control-Semigroupoid.purs new file mode 100644 index 0000000000..729e1bbe04 --- /dev/null +++ b/tests/support/flattened/Control-Semigroupoid.purs @@ -0,0 +1,24 @@ +module Control.Semigroupoid where + +-- | A `Semigroupoid` is similar to a [`Category`](#category) but does not +-- | require an identity element `id`, just composable morphisms. +-- | +-- | `Semigroupoid`s must satisfy the following law: +-- | +-- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r` +-- | +-- | One example of a `Semigroupoid` is the function type constructor `(->)`, +-- | with `(<<<)` defined as function composition. +class Semigroupoid a where + compose :: forall b c d. a c d -> a b c -> a b d + +instance semigroupoidFn :: Semigroupoid (->) where + compose f g x = f (g x) + +infixr 9 compose as <<< + +-- | Forwards composition, or `compose` with its arguments reversed. +composeFlipped :: forall a b c d. Semigroupoid a => a b c -> a c d -> a b d +composeFlipped f g = compose g f + +infixr 9 composeFlipped as >>> diff --git a/tests/support/flattened/Data-Boolean.purs b/tests/support/flattened/Data-Boolean.purs new file mode 100644 index 0000000000..9b4f6909a2 --- /dev/null +++ b/tests/support/flattened/Data-Boolean.purs @@ -0,0 +1,10 @@ +module Data.Boolean where + +-- | An alias for `true`, which can be useful in guard clauses: +-- | +-- | ```purescript +-- | max x y | x >= y = x +-- | | otherwise = y +-- | ``` +otherwise :: Boolean +otherwise = true diff --git a/tests/support/flattened/Data-BooleanAlgebra.purs b/tests/support/flattened/Data-BooleanAlgebra.purs new file mode 100644 index 0000000000..573865ee06 --- /dev/null +++ b/tests/support/flattened/Data-BooleanAlgebra.purs @@ -0,0 +1,20 @@ +module Data.BooleanAlgebra + ( class BooleanAlgebra + , module Data.HeytingAlgebra + ) where + +import Data.HeytingAlgebra (class HeytingAlgebra, ff, tt, implies, conj, disj, not) +import Data.Unit (Unit) + +-- | The `BooleanAlgebra` type class represents types that behave like boolean +-- | values. +-- | +-- | Instances should satisfy the following laws in addition to the +-- | `HeytingAlgebra` law: +-- | +-- | - Excluded middle: +-- | - `a || not a = tt` +class HeytingAlgebra a <= BooleanAlgebra a + +instance booleanAlgebraBoolean :: BooleanAlgebra Boolean +instance booleanAlgebraUnit :: BooleanAlgebra Unit diff --git a/tests/support/flattened/Data-Bounded.js b/tests/support/flattened/Data-Bounded.js new file mode 100644 index 0000000000..c4b028f888 --- /dev/null +++ b/tests/support/flattened/Data-Bounded.js @@ -0,0 +1,9 @@ +"use strict"; + +// module Data.Bounded + +exports.topInt = 2147483647; +exports.bottomInt = -2147483648; + +exports.topChar = String.fromCharCode(65535); +exports.bottomChar = String.fromCharCode(0); diff --git a/tests/support/flattened/Data-Bounded.purs b/tests/support/flattened/Data-Bounded.purs new file mode 100644 index 0000000000..36959da6d2 --- /dev/null +++ b/tests/support/flattened/Data-Bounded.purs @@ -0,0 +1,46 @@ +module Data.Bounded + ( class Bounded + , bottom + , top + , module Data.Ord + ) where + +import Data.Ord (class Ord, Ordering(..), compare, (<), (<=), (>), (>=)) +import Data.Unit (Unit, unit) + +-- | The `Bounded` type class represents totally ordered types that have an +-- | upper and lower boundary. +-- | +-- | Instances should satisfy the following law in addition to the `Ord` laws: +-- | +-- | - Bounded: `bottom <= a <= top` +class Ord a <= Bounded a where + top :: a + bottom :: a + +instance boundedBoolean :: Bounded Boolean where + top = true + bottom = false + +instance boundedInt :: Bounded Int where + top = topInt + bottom = bottomInt + +foreign import topInt :: Int +foreign import bottomInt :: Int + +-- | Characters fall within the Unicode range. +instance boundedChar :: Bounded Char where + top = topChar + bottom = bottomChar + +foreign import topChar :: Char +foreign import bottomChar :: Char + +instance boundedOrdering :: Bounded Ordering where + top = GT + bottom = LT + +instance boundedUnit :: Bounded Unit where + top = unit + bottom = unit diff --git a/tests/support/flattened/Data-CommutativeRing.purs b/tests/support/flattened/Data-CommutativeRing.purs new file mode 100644 index 0000000000..68cc61ca7d --- /dev/null +++ b/tests/support/flattened/Data-CommutativeRing.purs @@ -0,0 +1,22 @@ +module Data.CommutativeRing + ( class CommutativeRing + , module Data.Ring + , module Data.Semiring + ) where + +import Data.Ring (class Ring) +import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+)) +import Data.Unit (Unit) + +-- | The `CommutativeRing` class is for rings where multiplication is +-- | commutative. +-- | +-- | Instances must satisfy the following law in addition to the `Ring` +-- | laws: +-- | +-- | - Commutative multiplication: `a * b = b * a` +class Ring a <= CommutativeRing a + +instance commutativeRingInt :: CommutativeRing Int +instance commutativeRingNumber :: CommutativeRing Number +instance commutativeRingUnit :: CommutativeRing Unit diff --git a/tests/support/flattened/Data-Eq.js b/tests/support/flattened/Data-Eq.js new file mode 100644 index 0000000000..16c7c671c8 --- /dev/null +++ b/tests/support/flattened/Data-Eq.js @@ -0,0 +1,27 @@ +"use strict"; + +// module Data.Eq + +exports.refEq = function (r1) { + return function (r2) { + return r1 === r2; + }; +}; + +exports.refIneq = function (r1) { + return function (r2) { + return r1 !== r2; + }; +}; + +exports.eqArrayImpl = function (f) { + return function (xs) { + return function (ys) { + if (xs.length !== ys.length) return false; + for (var i = 0; i < xs.length; i++) { + if (!f(xs[i])(ys[i])) return false; + } + return true; + }; + }; +}; diff --git a/tests/support/flattened/Data-Eq.purs b/tests/support/flattened/Data-Eq.purs new file mode 100644 index 0000000000..33d4a7e1e8 --- /dev/null +++ b/tests/support/flattened/Data-Eq.purs @@ -0,0 +1,51 @@ +module Data.Eq (class Eq, eq, (==), notEq, (/=)) where + +import Data.Unit (Unit) +import Data.Void (Void) + +-- | The `Eq` type class represents types which support decidable equality. +-- | +-- | `Eq` instances should satisfy the following laws: +-- | +-- | - Reflexivity: `x == x = true` +-- | - Symmetry: `x == y = y == x` +-- | - Transitivity: if `x == y` and `y == z` then `x == z` +class Eq a where + eq :: a -> a -> Boolean + +infix 4 eq as == + +-- | `notEq` tests whether one value is _not equal_ to another. Shorthand for +-- | `not (eq x y)`. +notEq :: forall a. Eq a => a -> a -> Boolean +notEq x y = (x == y) == false + +infix 4 notEq as /= + +instance eqBoolean :: Eq Boolean where + eq = refEq + +instance eqInt :: Eq Int where + eq = refEq + +instance eqNumber :: Eq Number where + eq = refEq + +instance eqChar :: Eq Char where + eq = refEq + +instance eqString :: Eq String where + eq = refEq + +instance eqUnit :: Eq Unit where + eq _ _ = true + +instance eqVoid :: Eq Void where + eq _ _ = true + +instance eqArray :: Eq a => Eq (Array a) where + eq = eqArrayImpl eq + +foreign import refEq :: forall a. a -> a -> Boolean +foreign import refIneq :: forall a. a -> a -> Boolean +foreign import eqArrayImpl :: forall a. (a -> a -> Boolean) -> Array a -> Array a -> Boolean diff --git a/tests/support/flattened/Data-EuclideanRing.js b/tests/support/flattened/Data-EuclideanRing.js new file mode 100644 index 0000000000..6c89baee53 --- /dev/null +++ b/tests/support/flattened/Data-EuclideanRing.js @@ -0,0 +1,26 @@ +"use strict"; + +// module Data.EuclideanRing + +exports.intDegree = function (x) { + return Math.abs(x); +}; + +exports.intDiv = function (x) { + return function (y) { + /* jshint bitwise: false */ + return x / y | 0; + }; +}; + +exports.intMod = function (x) { + return function (y) { + return x % y; + }; +}; + +exports.numDiv = function (n1) { + return function (n2) { + return n1 / n2; + }; +}; diff --git a/tests/support/flattened/Data-EuclideanRing.purs b/tests/support/flattened/Data-EuclideanRing.purs new file mode 100644 index 0000000000..24df1d8312 --- /dev/null +++ b/tests/support/flattened/Data-EuclideanRing.purs @@ -0,0 +1,47 @@ +module Data.EuclideanRing + ( class EuclideanRing, degree, div, mod, (/) + , module Data.CommutativeRing + , module Data.Ring + , module Data.Semiring + ) where + +import Data.CommutativeRing (class CommutativeRing) +import Data.Ring (class Ring, sub, (-)) +import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+)) +import Data.Unit (Unit, unit) + +-- | The `EuclideanRing` class is for commutative rings that support division. +-- | +-- | Instances must satisfy the following law in addition to the `Ring` +-- | laws: +-- | +-- | - Integral domain: `a /= 0` and `b /= 0` implies `a * b /= 0` +-- | - Multiplicative Euclidean function: ``a = (a / b) * b + (a `mod` b)`` +-- | where `degree a > 0` and `degree a <= degree (a * b)` +class CommutativeRing a <= EuclideanRing a where + degree :: a -> Int + div :: a -> a -> a + mod :: a -> a -> a + +infixl 7 div as / + +instance euclideanRingInt :: EuclideanRing Int where + degree = intDegree + div = intDiv + mod = intMod + +instance euclideanRingNumber :: EuclideanRing Number where + degree _ = 1 + div = numDiv + mod _ _ = 0.0 + +instance euclideanRingUnit :: EuclideanRing Unit where + degree _ = 1 + div _ _ = unit + mod _ _ = unit + +foreign import intDegree :: Int -> Int +foreign import intDiv :: Int -> Int -> Int +foreign import intMod :: Int -> Int -> Int + +foreign import numDiv :: Number -> Number -> Number diff --git a/tests/support/flattened/Data-Field.purs b/tests/support/flattened/Data-Field.purs new file mode 100644 index 0000000000..2ee1a50cea --- /dev/null +++ b/tests/support/flattened/Data-Field.purs @@ -0,0 +1,24 @@ +module Data.Field + ( class Field + , module Data.CommutativeRing + , module Data.EuclideanRing + , module Data.Ring + , module Data.Semiring + ) where + +import Data.CommutativeRing (class CommutativeRing) +import Data.EuclideanRing (class EuclideanRing, degree, div, mod, (/)) +import Data.Ring (class Ring, negate, sub) +import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+)) +import Data.Unit (Unit) + +-- | The `Field` class is for types that are commutative fields. +-- | +-- | Instances must satisfy the following law in addition to the +-- | `CommutativeRing` and `EuclideanRing` laws: +-- | +-- | - Non-zero multiplicative inverse: ``a `mod` b = 0` for all `a` and `b` +class (CommutativeRing a, EuclideanRing a) <= Field a + +instance fieldNumber :: Field Number +instance fieldUnit :: Field Unit diff --git a/tests/support/flattened/Data-Function.js b/tests/support/flattened/Data-Function-Uncurried.js similarity index 99% rename from tests/support/flattened/Data-Function.js rename to tests/support/flattened/Data-Function-Uncurried.js index 0d6d0f4ede..a4e62b59e8 100644 --- a/tests/support/flattened/Data-Function.js +++ b/tests/support/flattened/Data-Function-Uncurried.js @@ -1,7 +1,6 @@ -/* global exports */ "use strict"; -// module Data.Function +// module Data.Function.Uncurried exports.mkFn0 = function (fn) { return function () { diff --git a/tests/support/flattened/Data-Function-Uncurried.purs b/tests/support/flattened/Data-Function-Uncurried.purs new file mode 100644 index 0000000000..edfb1f8784 --- /dev/null +++ b/tests/support/flattened/Data-Function-Uncurried.purs @@ -0,0 +1,102 @@ +module Data.Function.Uncurried where + +import Data.Unit (Unit) + +-- | A function of zero arguments +foreign import data Fn0 :: * -> * + +-- | A function of one argument +foreign import data Fn1 :: * -> * -> * + +-- | A function of two arguments +foreign import data Fn2 :: * -> * -> * -> * + +-- | A function of three arguments +foreign import data Fn3 :: * -> * -> * -> * -> * + +-- | A function of four arguments +foreign import data Fn4 :: * -> * -> * -> * -> * -> * + +-- | A function of five arguments +foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> * + +-- | A function of six arguments +foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> * + +-- | A function of seven arguments +foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> * + +-- | A function of eight arguments +foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * + +-- | A function of nine arguments +foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * + +-- | A function of ten arguments +foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * + +-- | Create a function of no arguments +foreign import mkFn0 :: forall a. (Unit -> a) -> Fn0 a + +-- | Create a function of one argument +foreign import mkFn1 :: forall a b. (a -> b) -> Fn1 a b + +-- | Create a function of two arguments from a curried function +foreign import mkFn2 :: forall a b c. (a -> b -> c) -> Fn2 a b c + +-- | Create a function of three arguments from a curried function +foreign import mkFn3 :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d + +-- | Create a function of four arguments from a curried function +foreign import mkFn4 :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e + +-- | Create a function of five arguments from a curried function +foreign import mkFn5 :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f + +-- | Create a function of six arguments from a curried function +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 + +-- | Create a function of seven arguments from a curried function +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 + +-- | Create a function of eight arguments from a curried function +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 + +-- | Create a function of nine arguments from a curried function +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 + +-- | Create a function of ten arguments from a curried function +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 + +-- | Apply a function of no arguments +foreign import runFn0 :: forall a. Fn0 a -> a + +-- | Apply a function of one argument +foreign import runFn1 :: forall a b. Fn1 a b -> a -> b + +-- | Apply a function of two arguments +foreign import runFn2 :: forall a b c. Fn2 a b c -> a -> b -> c + +-- | Apply a function of three arguments +foreign import runFn3 :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d + +-- | Apply a function of four arguments +foreign import runFn4 :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e + +-- | Apply a function of five arguments +foreign import runFn5 :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f + +-- | Apply a function of six arguments +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 + +-- | Apply a function of seven arguments +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 + +-- | Apply a function of eight arguments +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 + +-- | Apply a function of nine arguments +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 + +-- | Apply a function of ten arguments +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 diff --git a/tests/support/flattened/Data-Function.purs b/tests/support/flattened/Data-Function.purs index 37ceca1aa0..f3f067d914 100644 --- a/tests/support/flattened/Data-Function.purs +++ b/tests/support/flattened/Data-Function.purs @@ -1,6 +1,81 @@ -module Data.Function where +module Data.Function + ( flip + , const + , apply, ($) + , applyFlipped, (#) + , on + , module Control.Category + ) where + +import Control.Category (id, compose, (<<<), (>>>)) + +-- | Flips the order of the arguments to a function of two arguments. +-- | +-- | ```purescript +-- | flip const 1 2 = const 2 1 = 2 +-- | ``` +flip :: forall a b c. (a -> b -> c) -> b -> a -> c +flip f b a = f a b -import Prelude +-- | Returns its first argument and ignores its second. +-- | +-- | ```purescript +-- | const 1 "hello" = 1 +-- | ``` +const :: forall a b. a -> b -> a +const a _ = a + +-- | Applies a function to an argument. This is primarily used as the operator +-- | `($)` which allows parentheses to be omitted in some cases, or as a +-- | natural way to apply a chain of composed functions to a value. +apply :: forall a b. (a -> b) -> a -> b +apply f x = f x + +-- | Applies a function to an argument: the reverse of `(#)`. +-- | +-- | ```purescript +-- | length $ groupBy productCategory $ filter isInStock $ products +-- | ``` +-- | +-- | is equivalent to: +-- | +-- | ```purescript +-- | length (groupBy productCategory (filter isInStock products)) +-- | ``` +-- | +-- | Or another alternative equivalent, applying chain of composed functions to +-- | a value: +-- | +-- | ```purescript +-- | length <<< groupBy productCategory <<< filter isInStock $ products +-- | ``` +infixr 0 apply as $ + +-- | Applies an argument to a function. This is primarily used as the `(#)` +-- | operator, which allows parentheses to be ommitted in some cases, or as a +-- | natural way to apply a value to a chain of composed functions. +applyFlipped :: forall a b. a -> (a -> b) -> b +applyFlipped x f = f x + +-- | Applies an argument to a function: the reverse of `($)`. +-- | +-- | ```purescript +-- | products # filter isInStock # groupBy productCategory # length +-- | ``` +-- | +-- | is equivalent to: +-- | +-- | ```purescript +-- | length (groupBy productCategory (filter isInStock products)) +-- | ``` +-- | +-- | Or another alternative equivalent, applying a value to a chain of composed +-- | functions: +-- | +-- | ```purescript +-- | products # filter isInStock >>> groupBy productCategory >>> length +-- | ``` +infixl 1 applyFlipped as # -- | The `on` function is used to change the domain of a binary operator. -- | @@ -12,102 +87,3 @@ import Prelude -- | ``` on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c on f g x y = g x `f` g y - --- | A function of zero arguments -foreign import data Fn0 :: * -> * - --- | A function of one argument -foreign import data Fn1 :: * -> * -> * - --- | A function of two arguments -foreign import data Fn2 :: * -> * -> * -> * - --- | A function of three arguments -foreign import data Fn3 :: * -> * -> * -> * -> * - --- | A function of four arguments -foreign import data Fn4 :: * -> * -> * -> * -> * -> * - --- | A function of five arguments -foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> * - --- | A function of six arguments -foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> * - --- | A function of seven arguments -foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> * - --- | A function of eight arguments -foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * - --- | A function of nine arguments -foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * - --- | A function of ten arguments -foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * - --- | Create a function of no arguments -foreign import mkFn0 :: forall a. (Unit -> a) -> Fn0 a - --- | Create a function of one argument -foreign import mkFn1 :: forall a b. (a -> b) -> Fn1 a b - --- | Create a function of two arguments from a curried function -foreign import mkFn2 :: forall a b c. (a -> b -> c) -> Fn2 a b c - --- | Create a function of three arguments from a curried function -foreign import mkFn3 :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d - --- | Create a function of four arguments from a curried function -foreign import mkFn4 :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e - --- | Create a function of five arguments from a curried function -foreign import mkFn5 :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f - --- | Create a function of six arguments from a curried function -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 - --- | Create a function of seven arguments from a curried function -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 - --- | Create a function of eight arguments from a curried function -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 - --- | Create a function of nine arguments from a curried function -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 - --- | Create a function of ten arguments from a curried function -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 - --- | Apply a function of no arguments -foreign import runFn0 :: forall a. Fn0 a -> a - --- | Apply a function of one argument -foreign import runFn1 :: forall a b. Fn1 a b -> a -> b - --- | Apply a function of two arguments -foreign import runFn2 :: forall a b c. Fn2 a b c -> a -> b -> c - --- | Apply a function of three arguments -foreign import runFn3 :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d - --- | Apply a function of four arguments -foreign import runFn4 :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e - --- | Apply a function of five arguments -foreign import runFn5 :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f - --- | Apply a function of six arguments -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 - --- | Apply a function of seven arguments -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 - --- | Apply a function of eight arguments -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 - --- | Apply a function of nine arguments -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 - --- | Apply a function of ten arguments -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 diff --git a/tests/support/flattened/Data-Functor.js b/tests/support/flattened/Data-Functor.js new file mode 100644 index 0000000000..96f11fd120 --- /dev/null +++ b/tests/support/flattened/Data-Functor.js @@ -0,0 +1,14 @@ +"use strict"; + +// module Data.Functor + +exports.arrayMap = function (f) { + return function (arr) { + var l = arr.length; + var result = new Array(l); + for (var i = 0; i < l; i++) { + result[i] = f(arr[i]); + } + return result; + }; +}; diff --git a/tests/support/flattened/Data-Functor.purs b/tests/support/flattened/Data-Functor.purs new file mode 100644 index 0000000000..782e1dc28b --- /dev/null +++ b/tests/support/flattened/Data-Functor.purs @@ -0,0 +1,72 @@ +module Data.Functor + ( class Functor, map, (<$>) + , mapFlipped, (<#>) + , void + , voidRight, (<$) + , voidLeft, ($>) + ) where + +import Data.Function (const, compose) +import Data.Unit (Unit, unit) + +-- | A `Functor` is a type constructor which supports a mapping operation +-- | `(<$>)`. +-- | +-- | `(<$>)` can be used to turn functions `a -> b` into functions +-- | `f a -> f b` whose argument and return types use the type constructor `f` +-- | to represent some computational context. +-- | +-- | Instances must satisfy the following laws: +-- | +-- | - Identity: `(<$>) id = id` +-- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)` +class Functor f where + map :: forall a b. (a -> b) -> f a -> f b + +infixl 4 map as <$> + +-- | `mapFlipped` is `map` with its arguments reversed. For example: +-- | +-- | ```purescript +-- | [1, 2, 3] <#> \n -> n * n +-- | ``` +mapFlipped :: forall f a b. Functor f => f a -> (a -> b) -> f b +mapFlipped fa f = f <$> fa + +infixl 1 mapFlipped as <#> + +instance functorFn :: Functor ((->) r) where + map = compose + +instance functorArray :: Functor Array where + map = arrayMap + +foreign import arrayMap :: forall a b. (a -> b) -> Array a -> Array b + +-- | The `void` function is used to ignore the type wrapped by a +-- | [`Functor`](#functor), replacing it with `Unit` and keeping only the type +-- | information provided by the type constructor itself. +-- | +-- | `void` is often useful when using `do` notation to change the return type +-- | of a monadic computation: +-- | +-- | ```purescript +-- | main = forE 1 10 \n -> void do +-- | print n +-- | print (n * n) +-- | ``` +void :: forall f a. Functor f => f a -> f Unit +void = map (const unit) + +-- | Ignore the return value of a computation, using the specified return value +-- | instead. +voidRight :: forall f a b. Functor f => a -> f b -> f a +voidRight x = map (const x) + +infixl 4 voidRight as <$ + +-- | A version of `voidLast` with its arguments flipped. +voidLeft :: forall f a b. Functor f => f a -> b -> f b +voidLeft f x = const x <$> f + +infixl 4 voidLeft as $> diff --git a/tests/support/flattened/Data-HeytingAlgebra.js b/tests/support/flattened/Data-HeytingAlgebra.js new file mode 100644 index 0000000000..04981ea1ac --- /dev/null +++ b/tests/support/flattened/Data-HeytingAlgebra.js @@ -0,0 +1,19 @@ +"use strict"; + +// module Data.HeytingAlgebra + +exports.boolConj = function (b1) { + return function (b2) { + return b1 && b2; + }; +}; + +exports.boolDisj = function (b1) { + return function (b2) { + return b1 || b2; + }; +}; + +exports.boolNot = function (b) { + return !b; +}; diff --git a/tests/support/flattened/Data-HeytingAlgebra.purs b/tests/support/flattened/Data-HeytingAlgebra.purs new file mode 100644 index 0000000000..eb17e83432 --- /dev/null +++ b/tests/support/flattened/Data-HeytingAlgebra.purs @@ -0,0 +1,70 @@ +module Data.HeytingAlgebra + ( class HeytingAlgebra, tt, ff, implies, conj, disj, not + , (&&), (||) + ) where + +import Data.Unit (Unit, unit) + +-- | The `HeytingAlgebra` type class represents types are bounded lattices with +-- | an implication operator such that the following laws hold: +-- | +-- | - Associativity: +-- | - `a || (b || c) = (a || b) || c` +-- | - `a && (b && c) = (a && b) && c` +-- | - Commutativity: +-- | - `a || b = b || a` +-- | - `a && b = b && a` +-- | - Absorption: +-- | - `a || (a && b) = a` +-- | - `a && (a || b) = a` +-- | - Idempotent: +-- | - `a || a = a` +-- | - `a && a = a` +-- | - Identity: +-- | - `a || ff = a` +-- | - `a && tt = a` +-- | - Implication: +-- | - ``a `implies` a = tt`` +-- | - ``a && (a `implies` b) = a && b`` +-- | - ``b && (a `implies` b) = b`` +-- | - ``a `implies` (b && c) = (a `implies` b) && (a `implies` c)`` +-- | - Complemented: +-- | - ``not a = a `implies` ff`` +class HeytingAlgebra a where + ff :: a + tt :: a + implies :: a -> a -> a + conj :: a -> a -> a + disj :: a -> a -> a + not :: a -> a + +infixr 3 conj as && +infixr 2 disj as || + +instance heytingAlgebraBoolean :: HeytingAlgebra Boolean where + ff = false + tt = true + implies a b = not a || b + conj = boolConj + disj = boolDisj + not = boolNot + +instance heytingAlgebraUnit :: HeytingAlgebra Unit where + ff = unit + tt = unit + implies _ _ = unit + conj _ _ = unit + disj _ _ = unit + not _ = unit + +instance heytingAlgebraFunction :: HeytingAlgebra b => HeytingAlgebra (a -> b) where + ff _ = ff + tt _ = tt + implies f g a = f a `implies` g a + conj f g a = f a && g a + disj f g a = f a || g a + not f a = not (f a) + +foreign import boolConj :: Boolean -> Boolean -> Boolean +foreign import boolDisj :: Boolean -> Boolean -> Boolean +foreign import boolNot :: Boolean -> Boolean diff --git a/tests/support/flattened/Data-Ord-Unsafe.js b/tests/support/flattened/Data-Ord-Unsafe.js new file mode 100644 index 0000000000..229c005841 --- /dev/null +++ b/tests/support/flattened/Data-Ord-Unsafe.js @@ -0,0 +1,15 @@ +"use strict"; + +// module Data.Ord.Unsafe + +exports.unsafeCompareImpl = function (lt) { + return function (eq) { + return function (gt) { + return function (x) { + return function (y) { + return x < y ? lt : x > y ? gt : eq; + }; + }; + }; + }; +}; diff --git a/tests/support/flattened/Data-Ord-Unsafe.purs b/tests/support/flattened/Data-Ord-Unsafe.purs new file mode 100644 index 0000000000..dcb30401aa --- /dev/null +++ b/tests/support/flattened/Data-Ord-Unsafe.purs @@ -0,0 +1,15 @@ +module Data.Ord.Unsafe (unsafeCompare) where + +import Data.Ordering (Ordering(..)) + +unsafeCompare :: forall a. a -> a -> Ordering +unsafeCompare = unsafeCompareImpl LT EQ GT + +foreign import unsafeCompareImpl + :: forall a + . Ordering + -> Ordering + -> Ordering + -> a + -> a + -> Ordering diff --git a/tests/support/flattened/Data-Ord.js b/tests/support/flattened/Data-Ord.js new file mode 100644 index 0000000000..ad8306fc1c --- /dev/null +++ b/tests/support/flattened/Data-Ord.js @@ -0,0 +1,41 @@ +"use strict"; + +// module Data.Ord + +exports.ordArrayImpl = function (f) { + return function (xs) { + return function (ys) { + var i = 0; + var xlen = xs.length; + var ylen = ys.length; + while (i < xlen && i < ylen) { + var x = xs[i]; + var y = ys[i]; + var o = f(x)(y); + if (o !== 0) { + return o; + } + i++; + } + if (xlen === ylen) { + return 0; + } else if (xlen > ylen) { + return -1; + } else { + return 1; + } + }; + }; +}; + +exports.unsafeCompareImpl = function (lt) { + return function (eq) { + return function (gt) { + return function (x) { + return function (y) { + return x < y ? lt : x > y ? gt : eq; + }; + }; + }; + }; +}; diff --git a/tests/support/flattened/Data-Ord.purs b/tests/support/flattened/Data-Ord.purs new file mode 100644 index 0000000000..e8548cda4e --- /dev/null +++ b/tests/support/flattened/Data-Ord.purs @@ -0,0 +1,153 @@ +module Data.Ord + ( class Ord, compare + , lessThan, (<) + , lessThanOrEq, (<=) + , greaterThan, (>) + , greaterThanOrEq, (>=) + , comparing + , min, max + , clamp + , between + , module Data.Ordering + ) where + +import Data.Eq (class Eq) +import Data.Function (on) +import Data.Ord.Unsafe (unsafeCompare) +import Data.Ordering (Ordering(..)) +import Data.Ring (negate) +import Data.Semigroup (class Semigroup) +import Data.Show (class Show) +import Data.Unit (Unit) +import Data.Void (Void) + +-- | The `Ord` type class represents types which support comparisons with a +-- | _total order_. +-- | +-- | `Ord` instances should satisfy the laws of total orderings: +-- | +-- | - Reflexivity: `a <= a` +-- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b` +-- | - Transitivity: if `a <= b` and `b <= c` then `a <= c` +class Eq a <= Ord a where + compare :: a -> a -> Ordering + +instance ordBoolean :: Ord Boolean where + compare = unsafeCompare + +instance ordInt :: Ord Int where + compare = unsafeCompare + +instance ordNumber :: Ord Number where + compare = unsafeCompare + +instance ordString :: Ord String where + compare = unsafeCompare + +instance ordChar :: Ord Char where + compare = unsafeCompare + +instance ordUnit :: Ord Unit where + compare _ _ = EQ + +instance ordVoid :: Ord Void where + compare _ _ = EQ + +instance ordArray :: Ord a => Ord (Array a) where + compare = \xs ys -> compare 0 (ordArrayImpl toDelta xs ys) + where + toDelta x y = + case compare x y of + EQ -> 0 + LT -> 1 + GT -> -1 + +foreign import ordArrayImpl :: forall a. (a -> a -> Int) -> Array a -> Array a -> Int + +instance ordOrdering :: Ord Ordering where + compare LT LT = EQ + compare EQ EQ = EQ + compare GT GT = EQ + compare LT _ = LT + compare EQ LT = GT + compare EQ GT = LT + compare GT _ = GT + +-- | Test whether one value is _strictly less than_ another. +lessThan :: forall a. Ord a => a -> a -> Boolean +lessThan a1 a2 = case a1 `compare` a2 of + LT -> true + _ -> false + +-- | Test whether one value is _strictly greater than_ another. +greaterThan :: forall a. Ord a => a -> a -> Boolean +greaterThan a1 a2 = case a1 `compare` a2 of + GT -> true + _ -> false + +-- | Test whether one value is _non-strictly less than_ another. +lessThanOrEq :: forall a. Ord a => a -> a -> Boolean +lessThanOrEq a1 a2 = case a1 `compare` a2 of + GT -> false + _ -> true + +-- | Test whether one value is _non-strictly greater than_ another. +greaterThanOrEq :: forall a. Ord a => a -> a -> Boolean +greaterThanOrEq a1 a2 = case a1 `compare` a2 of + LT -> false + _ -> true + +infixl 4 lessThan as < +infixl 4 lessThanOrEq as <= +infixl 4 greaterThan as > +infixl 4 greaterThanOrEq as >= + +-- | Compares two values by mapping them to a type with an `Ord` instance. +comparing :: forall a b. Ord b => (a -> b) -> (a -> a -> Ordering) +comparing f = compare `on` f + +-- | Take the minimum of two values. If they are considered equal, the first +-- | argument is chosen. +min :: forall a. Ord a => a -> a -> a +min x y = + case compare x y of + LT -> x + EQ -> x + GT -> y + +-- | Take the maximum of two values. If they are considered equal, the first +-- | argument is chosen. +max :: forall a. Ord a => a -> a -> a +max x y = + case compare x y of + LT -> y + EQ -> x + GT -> x + +-- | Clamp a value between a minimum and a maximum. For example: +-- | +-- | ``` purescript +-- | let f = clamp 0 10 +-- | f (-5) == 0 +-- | f 5 == 5 +-- | f 15 == 10 +-- | ``` +clamp :: forall a. Ord a => a -> a -> a -> a +clamp low hi x = min hi (max low x) + +-- | Test whether a value is between a minimum and a maximum (inclusive). +-- | For example: +-- | +-- | ``` purescript +-- | let f = between 0 10 +-- | f 0 == true +-- | f (-5) == false +-- | f 5 == true +-- | f 10 == true +-- | f 15 == false +-- | ``` +between :: forall a. Ord a => a -> a -> a -> Boolean +between low hi x + | x < low = false + | x > hi = false + | true = true diff --git a/tests/support/flattened/Data-Ordering.purs b/tests/support/flattened/Data-Ordering.purs new file mode 100644 index 0000000000..61f0ae9384 --- /dev/null +++ b/tests/support/flattened/Data-Ordering.purs @@ -0,0 +1,36 @@ +module Data.Ordering (Ordering(..), invert) where + +import Data.Eq (class Eq) +import Data.Semigroup (class Semigroup) +import Data.Show (class Show) + +-- | The `Ordering` data type represents the three possible outcomes of +-- | comparing two values: +-- | +-- | `LT` - The first value is _less than_ the second. +-- | `GT` - The first value is _greater than_ the second. +-- | `EQ` - The first value is _equal to_ the second. +data Ordering = LT | GT | EQ + +instance eqOrdering :: Eq Ordering where + eq LT LT = true + eq GT GT = true + eq EQ EQ = true + eq _ _ = false + +instance semigroupOrdering :: Semigroup Ordering where + append LT _ = LT + append GT _ = GT + append EQ y = y + +instance showOrdering :: Show Ordering where + show LT = "LT" + show GT = "GT" + show EQ = "EQ" + +-- | Reverses an `Ordering` value, flipping greater than for less than while +-- | preserving equality. +invert :: Ordering -> Ordering +invert GT = LT +invert EQ = EQ +invert LT = GT diff --git a/tests/support/flattened/Data-Ring.js b/tests/support/flattened/Data-Ring.js new file mode 100644 index 0000000000..e9186dfca1 --- /dev/null +++ b/tests/support/flattened/Data-Ring.js @@ -0,0 +1,16 @@ +"use strict"; + +// module Data.Ring + +exports.intSub = function (x) { + return function (y) { + /* jshint bitwise: false */ + return x - y | 0; + }; +}; + +exports.numSub = function (n1) { + return function (n2) { + return n1 - n2; + }; +}; diff --git a/tests/support/flattened/Data-Ring.purs b/tests/support/flattened/Data-Ring.purs new file mode 100644 index 0000000000..3e988d8165 --- /dev/null +++ b/tests/support/flattened/Data-Ring.purs @@ -0,0 +1,35 @@ +module Data.Ring + ( class Ring, sub, negate, (-) + , module Data.Semiring + ) where + +import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+)) +import Data.Unit (Unit, unit) + +-- | The `Ring` class is for types that support addition, multiplication, +-- | and subtraction operations. +-- | +-- | Instances must satisfy the following law in addition to the `Semiring` +-- | laws: +-- | +-- | - Additive inverse: `a - a = (zero - a) + a = zero` +class Semiring a <= Ring a where + sub :: a -> a -> a + +infixl 6 sub as - + +instance ringInt :: Ring Int where + sub = intSub + +instance ringNumber :: Ring Number where + sub = numSub + +instance ringUnit :: Ring Unit where + sub _ _ = unit + +-- | `negate x` can be used as a shorthand for `zero - x`. +negate :: forall a. Ring a => a -> a +negate a = zero - a + +foreign import intSub :: Int -> Int -> Int +foreign import numSub :: Number -> Number -> Number diff --git a/tests/support/flattened/Data-Semigroup.js b/tests/support/flattened/Data-Semigroup.js new file mode 100644 index 0000000000..1075ce0ddf --- /dev/null +++ b/tests/support/flattened/Data-Semigroup.js @@ -0,0 +1,15 @@ +"use strict"; + +// module Data.Semigroup + +exports.concatString = function (s1) { + return function (s2) { + return s1 + s2; + }; +}; + +exports.concatArray = function (xs) { + return function (ys) { + return xs.concat(ys); + }; +}; diff --git a/tests/support/flattened/Data-Semigroup.purs b/tests/support/flattened/Data-Semigroup.purs new file mode 100644 index 0000000000..ec7ac20789 --- /dev/null +++ b/tests/support/flattened/Data-Semigroup.purs @@ -0,0 +1,35 @@ +module Data.Semigroup (class Semigroup, append, (<>)) where + +import Data.Unit (Unit, unit) +import Data.Void (Void, absurd) + +-- | The `Semigroup` type class identifies an associative operation on a type. +-- | +-- | Instances are required to satisfy the following law: +-- | +-- | - Associativity: `(x <> y) <> z = x <> (y <> z)` +-- | +-- | One example of a `Semigroup` is `String`, with `(<>)` defined as string +-- | concatenation. +class Semigroup a where + append :: a -> a -> a + +infixr 5 append as <> + +instance semigroupString :: Semigroup String where + append = concatString + +instance semigroupUnit :: Semigroup Unit where + append _ _ = unit + +instance semigroupVoid :: Semigroup Void where + append _ = absurd + +instance semigroupFn :: Semigroup s' => Semigroup (s -> s') where + append f g x = f x <> g x + +instance semigroupArray :: Semigroup (Array a) where + append = concatArray + +foreign import concatString :: String -> String -> String +foreign import concatArray :: forall a. Array a -> Array a -> Array a diff --git a/tests/support/flattened/Data-Semiring.js b/tests/support/flattened/Data-Semiring.js new file mode 100644 index 0000000000..2ce2b3d565 --- /dev/null +++ b/tests/support/flattened/Data-Semiring.js @@ -0,0 +1,29 @@ +"use strict"; + +// module Data.Semiring + +exports.intAdd = function (x) { + return function (y) { + /* jshint bitwise: false */ + return x + y | 0; + }; +}; + +exports.intMul = function (x) { + return function (y) { + /* jshint bitwise: false */ + return x * y | 0; + }; +}; + +exports.numAdd = function (n1) { + return function (n2) { + return n1 + n2; + }; +}; + +exports.numMul = function (n1) { + return function (n2) { + return n1 * n2; + }; +}; diff --git a/tests/support/flattened/Data-Semiring.purs b/tests/support/flattened/Data-Semiring.purs new file mode 100644 index 0000000000..47ae41b537 --- /dev/null +++ b/tests/support/flattened/Data-Semiring.purs @@ -0,0 +1,51 @@ +module Data.Semiring (class Semiring, add, (+), zero, mul, (*), one) where + +import Data.Unit (Unit, unit) + +-- | The `Semiring` class is for types that support an addition and +-- | multiplication operation. +-- | +-- | Instances must satisfy the following laws: +-- | +-- | - Commutative monoid under addition: +-- | - Associativity: `(a + b) + c = a + (b + c)` +-- | - Identity: `zero + a = a + zero = a` +-- | - Commutative: `a + b = b + a` +-- | - Monoid under multiplication: +-- | - Associativity: `(a * b) * c = a * (b * c)` +-- | - Identity: `one * a = a * one = a` +-- | - Multiplication distributes over addition: +-- | - Left distributivity: `a * (b + c) = (a * b) + (a * c)` +-- | - Right distributivity: `(a + b) * c = (a * c) + (b * c)` +-- | - Annihiliation: `zero * a = a * zero = zero` +class Semiring a where + add :: a -> a -> a + zero :: a + mul :: a -> a -> a + one :: a + +infixl 6 add as + +infixl 7 mul as * + +instance semiringInt :: Semiring Int where + add = intAdd + zero = 0 + mul = intMul + one = 1 + +instance semiringNumber :: Semiring Number where + add = numAdd + zero = 0.0 + mul = numMul + one = 1.0 + +instance semiringUnit :: Semiring Unit where + add _ _ = unit + zero = unit + mul _ _ = unit + one = unit + +foreign import intAdd :: Int -> Int -> Int +foreign import intMul :: Int -> Int -> Int +foreign import numAdd :: Number -> Number -> Number +foreign import numMul :: Number -> Number -> Number diff --git a/tests/support/flattened/Data-Show.js b/tests/support/flattened/Data-Show.js new file mode 100644 index 0000000000..68bbe76335 --- /dev/null +++ b/tests/support/flattened/Data-Show.js @@ -0,0 +1,63 @@ +"use strict"; + +// module Data.Show + +exports.showIntImpl = function (n) { + return n.toString(); +}; + +exports.showNumberImpl = function (n) { + /* jshint bitwise: false */ + return n === (n | 0) ? n + ".0" : n.toString(); +}; + +exports.showCharImpl = function (c) { + var code = c.charCodeAt(0); + if (code < 0x20 || code === 0x7F) { + switch (c) { + case "\a": return "'\\a'"; + case "\b": return "'\\b'"; + case "\f": return "'\\f'"; + case "\n": return "'\\n'"; + case "\r": return "'\\r'"; + case "\t": return "'\\t'"; + case "\v": return "'\\v'"; + } + return "'\\" + code.toString(10) + "'"; + } + return c === "'" || c === "\\" ? "'\\" + c + "'" : "'" + c + "'"; +}; + +exports.showStringImpl = function (s) { + var l = s.length; + return "\"" + s.replace( + /[\0-\x1F\x7F"\\]/g, + function (c, i) { // jshint ignore:line + switch (c) { + case "\"": + case "\\": + return "\\" + c; + case "\a": return "\\a"; + case "\b": return "\\b"; + case "\f": return "\\f"; + case "\n": return "\\n"; + case "\r": return "\\r"; + case "\t": return "\\t"; + case "\v": return "\\v"; + } + var k = i + 1; + var empty = k < l && s[k] >= "0" && s[k] <= "9" ? "\\&" : ""; + return "\\" + c.charCodeAt(0).toString(10) + empty; + } + ) + "\""; +}; + +exports.showArrayImpl = function (f) { + return function (xs) { + var ss = []; + for (var i = 0, l = xs.length; i < l; i++) { + ss[i] = f(xs[i]); + } + return "[" + ss.join(",") + "]"; + }; +}; diff --git a/tests/support/flattened/Data-Show.purs b/tests/support/flattened/Data-Show.purs new file mode 100644 index 0000000000..18ec08cfd6 --- /dev/null +++ b/tests/support/flattened/Data-Show.purs @@ -0,0 +1,35 @@ +module Data.Show (class Show, show) where + +-- | The `Show` type class represents those types which can be converted into +-- | a human-readable `String` representation. +-- | +-- | While not required, it is recommended that for any expression `x`, the +-- | string `show x` be executable PureScript code which evaluates to the same +-- | value as the expression `x`. +class Show a where + show :: a -> String + +instance showBoolean :: Show Boolean where + show true = "true" + show false = "false" + +instance showInt :: Show Int where + show = showIntImpl + +instance showNumber :: Show Number where + show = showNumberImpl + +instance showChar :: Show Char where + show = showCharImpl + +instance showString :: Show String where + show = showStringImpl + +instance showArray :: Show a => Show (Array a) where + show = showArrayImpl show + +foreign import showIntImpl :: Int -> String +foreign import showNumberImpl :: Number -> String +foreign import showCharImpl :: Char -> String +foreign import showStringImpl :: String -> String +foreign import showArrayImpl :: forall a. (a -> String) -> Array a -> String diff --git a/tests/support/flattened/Data-Unit.js b/tests/support/flattened/Data-Unit.js new file mode 100644 index 0000000000..0748554aaf --- /dev/null +++ b/tests/support/flattened/Data-Unit.js @@ -0,0 +1,5 @@ +"use strict"; + +// module Data.Unit + +exports.unit = {}; diff --git a/tests/support/flattened/Data-Unit.purs b/tests/support/flattened/Data-Unit.purs new file mode 100644 index 0000000000..d69e1fbb0d --- /dev/null +++ b/tests/support/flattened/Data-Unit.purs @@ -0,0 +1,17 @@ +module Data.Unit where + +import Data.Show (class Show) + +-- | The `Unit` type has a single inhabitant, called `unit`. It represents +-- | values with no computational content. +-- | +-- | `Unit` is often used, wrapped in a monadic type constructor, as the +-- | return type of a computation where only +-- | the _effects_ are important. +foreign import data Unit :: * + +-- | `unit` is the sole inhabitant of the `Unit` type. +foreign import unit :: Unit + +instance showUnit :: Show Unit where + show _ = "unit" diff --git a/tests/support/flattened/Data-Void.purs b/tests/support/flattened/Data-Void.purs new file mode 100644 index 0000000000..79922088db --- /dev/null +++ b/tests/support/flattened/Data-Void.purs @@ -0,0 +1,13 @@ +module Data.Void (Void, absurd) where + +import Data.Show (class Show) + +newtype Void = Void Void + +instance showVoid :: Show Void where + show = absurd + +absurd :: forall a. Void -> a +absurd a = spin a + where + spin (Void b) = spin b diff --git a/tests/support/flattened/Prelude.js b/tests/support/flattened/Prelude.js deleted file mode 100644 index 72a855a76c..0000000000 --- a/tests/support/flattened/Prelude.js +++ /dev/null @@ -1,228 +0,0 @@ -/* global exports */ -"use strict"; - -// module Prelude - -//- Functor -------------------------------------------------------------------- - -exports.arrayMap = function (f) { - return function (arr) { - var l = arr.length; - var result = new Array(l); - for (var i = 0; i < l; i++) { - result[i] = f(arr[i]); - } - return result; - }; -}; - -//- Bind ----------------------------------------------------------------------- - -exports.arrayBind = function (arr) { - return function (f) { - var result = []; - for (var i = 0, l = arr.length; i < l; i++) { - Array.prototype.push.apply(result, f(arr[i])); - } - return result; - }; -}; - -//- Monoid --------------------------------------------------------------------- - -exports.concatString = function (s1) { - return function (s2) { - return s1 + s2; - }; -}; - -exports.concatArray = function (xs) { - return function (ys) { - return xs.concat(ys); - }; -}; - -//- Semiring ------------------------------------------------------------------- - -exports.intAdd = function (x) { - return function (y) { - /* jshint bitwise: false */ - return x + y | 0; - }; -}; - -exports.intMul = function (x) { - return function (y) { - /* jshint bitwise: false */ - return x * y | 0; - }; -}; - -exports.numAdd = function (n1) { - return function (n2) { - return n1 + n2; - }; -}; - -exports.numMul = function (n1) { - return function (n2) { - return n1 * n2; - }; -}; - -//- ModuloSemiring ------------------------------------------------------------- - -exports.intDiv = function (x) { - return function (y) { - /* jshint bitwise: false */ - return x / y | 0; - }; -}; - -exports.intMod = function (x) { - return function (y) { - return x % y; - }; -}; - -exports.numDiv = function (n1) { - return function (n2) { - return n1 / n2; - }; -}; - -//- Ring ----------------------------------------------------------------------- - -exports.intSub = function (x) { - return function (y) { - /* jshint bitwise: false */ - return x - y | 0; - }; -}; - -exports.numSub = function (n1) { - return function (n2) { - return n1 - n2; - }; -}; - -//- Eq ------------------------------------------------------------------------- - -exports.refEq = function (r1) { - return function (r2) { - return r1 === r2; - }; -}; - -exports.refIneq = function (r1) { - return function (r2) { - return r1 !== r2; - }; -}; - -exports.eqArrayImpl = function (f) { - return function (xs) { - return function (ys) { - if (xs.length !== ys.length) return false; - for (var i = 0; i < xs.length; i++) { - if (!f(xs[i])(ys[i])) return false; - } - return true; - }; - }; -}; - -exports.ordArrayImpl = function (f) { - return function (xs) { - return function (ys) { - var i = 0; - var xlen = xs.length; - var ylen = ys.length; - while (i < xlen && i < ylen) { - var x = xs[i]; - var y = ys[i]; - var o = f(x)(y); - if (o !== 0) { - return o; - } - i++; - } - if (xlen === ylen) { - return 0; - } else if (xlen > ylen) { - return -1; - } else { - return 1; - } - }; - }; -}; - -//- Ord ------------------------------------------------------------------------ - -exports.unsafeCompareImpl = function (lt) { - return function (eq) { - return function (gt) { - return function (x) { - return function (y) { - return x < y ? lt : x > y ? gt : eq; - }; - }; - }; - }; -}; - -//- Bounded -------------------------------------------------------------------- - -exports.topInt = 2147483647; -exports.bottomInt = -2147483648; - -exports.topChar = String.fromCharCode(65535); -exports.bottomChar = String.fromCharCode(0); - -//- BooleanAlgebra ------------------------------------------------------------- - -exports.boolOr = function (b1) { - return function (b2) { - return b1 || b2; - }; -}; - -exports.boolAnd = function (b1) { - return function (b2) { - return b1 && b2; - }; -}; - -exports.boolNot = function (b) { - return !b; -}; - -//- Show ----------------------------------------------------------------------- - -exports.showIntImpl = function (n) { - return n.toString(); -}; - -exports.showNumberImpl = function (n) { - /* jshint bitwise: false */ - return n === (n | 0) ? n + ".0" : n.toString(); -}; - -exports.showCharImpl = function (c) { - return c === "'" ? "'\\''" : "'" + c + "'"; -}; - -exports.showStringImpl = function (s) { - return JSON.stringify(s); -}; - -exports.showArrayImpl = function (f) { - return function (xs) { - var ss = []; - for (var i = 0, l = xs.length; i < l; i++) { - ss[i] = f(xs[i]); - } - return "[" + ss.join(",") + "]"; - }; -}; diff --git a/tests/support/flattened/Prelude.purs b/tests/support/flattened/Prelude.purs index 21ec9095fa..c56e2ea5f5 100644 --- a/tests/support/flattened/Prelude.purs +++ b/tests/support/flattened/Prelude.purs @@ -1,872 +1,52 @@ module Prelude - ( Unit(), unit - , ($), (#) - , flip - , const - , asTypeOf - , otherwise - , Semigroupoid, compose, (<<<), (>>>) - , Category, id - , Functor, map, (<$>), (<#>), void - , Apply, apply, (<*>) - , Applicative, pure, liftA1 - , Bind, bind, (>>=) - , Monad, return, liftM1, ap - , Semigroup, append, (<>), (++) - , Semiring, add, zero, mul, one, (+), (*) - , ModuloSemiring, div, mod, (/) - , Ring, sub, negate, (-) - , Num - , DivisionRing - , Eq, eq, (==), (/=) - , Ordering(..), Ord, compare, (<), (>), (<=), (>=) - , unsafeCompare - , Bounded, top, bottom - , BoundedOrd - , BooleanAlgebra, conj, disj, not, (&&), (||) - , Show, show + ( module Control.Applicative + , module Control.Apply + , module Control.Bind + , module Control.Category + , module Control.Monad + , module Control.Semigroupoid + , module Data.Boolean + , module Data.BooleanAlgebra + , module Data.Bounded + , module Data.CommutativeRing + , module Data.Eq + , module Data.EuclideanRing + , module Data.Field + , module Data.Function + , module Data.Functor + , module Data.HeytingAlgebra + , module Data.Ord + , module Data.Ordering + , module Data.Ring + , module Data.Semigroup + , module Data.Semiring + , module Data.Show + , module Data.Unit + , module Data.Void ) where --- | The `Unit` type has a single inhabitant, called `unit`. It represents --- | values with no computational content. --- | --- | `Unit` is often used, wrapped in a monadic type constructor, as the --- | return type of a computation where only --- | the _effects_ are important. -newtype Unit = Unit {} - --- | `unit` is the sole inhabitant of the `Unit` type. -unit :: Unit -unit = Unit {} - -infixr 0 $ -infixl 1 # - --- | Applies a function to its argument. --- | --- | ```purescript --- | length $ groupBy productCategory $ filter isInStock $ products --- | ``` --- | --- | is equivalent to: --- | --- | ```purescript --- | length (groupBy productCategory (filter isInStock products)) --- | ``` --- | --- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of --- | left: `a $ b $ c $ d x = a $ (b $ (c $ (d $ x))) = a (b (c (d x)))` -($) :: forall a b. (a -> b) -> a -> b -($) f x = f x - --- | Applies an argument to a function. --- | --- | ```purescript --- | products # filter isInStock # groupBy productCategory # length --- | ``` --- | --- | is equivalent to: --- | --- | ```purescript --- | length (groupBy productCategory (filter isInStock products)) --- | ``` --- | --- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of --- | right: `x # a # b # c # d = (((x # a) # b) # c) # d = d (c (b (a x)))` -(#) :: forall a b. a -> (a -> b) -> b -(#) x f = f x - --- | Flips the order of the arguments to a function of two arguments. --- | --- | ```purescript --- | flip const 1 2 = const 2 1 = 2 --- | ``` -flip :: forall a b c. (a -> b -> c) -> b -> a -> c -flip f b a = f a b - --- | Returns its first argument and ignores its second. --- | --- | ```purescript --- | const 1 "hello" = 1 --- | ``` -const :: forall a b. a -> b -> a -const a _ = a - --- | This function returns its first argument, and can be used to assert type --- | equalities. This can be useful when types are otherwise ambiguous. --- | --- | ```purescript --- | main = print $ [] `asTypeOf` [0] --- | ``` --- | --- | If instead, we had written `main = print []`, the type of the argument --- | `[]` would have been ambiguous, resulting in a compile-time error. -asTypeOf :: forall a. a -> a -> a -asTypeOf x _ = x - --- | An alias for `true`, which can be useful in guard clauses: --- | --- | ```purescript --- | max x y | x >= y = x --- | | otherwise = y --- | ``` -otherwise :: Boolean -otherwise = true - --- | A `Semigroupoid` is similar to a [`Category`](#category) but does not --- | require an identity element `id`, just composable morphisms. --- | --- | `Semigroupoid`s must satisfy the following law: --- | --- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r` --- | --- | One example of a `Semigroupoid` is the function type constructor `(->)`, --- | with `(<<<)` defined as function composition. -class Semigroupoid a where - compose :: forall b c d. a c d -> a b c -> a b d - -instance semigroupoidFn :: Semigroupoid (->) where - compose f g x = f (g x) - -infixr 9 >>> -infixr 9 <<< - --- | `(<<<)` is an alias for `compose`. -(<<<) :: forall a b c d. (Semigroupoid a) => a c d -> a b c -> a b d -(<<<) = compose - --- | Forwards composition, or `(<<<)` with its arguments reversed. -(>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d -(>>>) = flip compose - --- | `Category`s consist of objects and composable morphisms between them, and --- | as such are [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids` --- | must have an identity element. --- | --- | Instances must satisfy the following law in addition to the --- | `Semigroupoid` law: --- | --- | - Identity: `id <<< p = p <<< id = p` -class (Semigroupoid a) <= Category a where - id :: forall t. a t t - -instance categoryFn :: Category (->) where - id x = x - --- | A `Functor` is a type constructor which supports a mapping operation --- | `(<$>)`. --- | --- | `(<$>)` can be used to turn functions `a -> b` into functions --- | `f a -> f b` whose argument and return types use the type constructor `f` --- | to represent some computational context. --- | --- | Instances must satisfy the following laws: --- | --- | - Identity: `(<$>) id = id` --- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)` -class Functor f where - map :: forall a b. (a -> b) -> f a -> f b - -instance functorFn :: Functor ((->) r) where - map = compose - -instance functorArray :: Functor Array where - map = arrayMap - -foreign import arrayMap :: forall a b. (a -> b) -> Array a -> Array b - -infixl 4 <$> -infixl 1 <#> - --- | `(<$>)` is an alias for `map` -(<$>) :: forall f a b. (Functor f) => (a -> b) -> f a -> f b -(<$>) = map - --- | `(<#>)` is `(<$>)` with its arguments reversed. For example: --- | --- | ```purescript --- | [1, 2, 3] <#> \n -> n * n --- | ``` -(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b -(<#>) fa f = f <$> fa - --- | The `void` function is used to ignore the type wrapped by a --- | [`Functor`](#functor), replacing it with `Unit` and keeping only the type --- | information provided by the type constructor itself. --- | --- | `void` is often useful when using `do` notation to change the return type --- | of a monadic computation: --- | --- | ```purescript --- | main = forE 1 10 \n -> void do --- | print n --- | print (n * n) --- | ``` -void :: forall f a. (Functor f) => f a -> f Unit -void fa = const unit <$> fa - --- | The `Apply` class provides the `(<*>)` which is used to apply a function --- | to an argument under a type constructor. --- | --- | `Apply` can be used to lift functions of two or more arguments to work on --- | values wrapped with the type constructor `f`. It might also be understood --- | in terms of the `lift2` function: --- | --- | ```purescript --- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c --- | lift2 f a b = f <$> a <*> b --- | ``` --- | --- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts --- | the function application operator `($)` to arguments wrapped with the --- | type constructor `f`. --- | --- | Instances must satisfy the following law in addition to the `Functor` --- | laws: --- | --- | - Associative composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)` --- | --- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor. -class (Functor f) <= Apply f where - apply :: forall a b. f (a -> b) -> f a -> f b - -instance applyFn :: Apply ((->) r) where - apply f g x = f x (g x) - -instance applyArray :: Apply Array where - apply = ap - -infixl 4 <*> - --- | `(<*>)` is an alias for `apply`. -(<*>) :: forall f a b. (Apply f) => f (a -> b) -> f a -> f b -(<*>) = apply - --- | The `Applicative` type class extends the [`Apply`](#apply) type class --- | with a `pure` function, which can be used to create values of type `f a` --- | from values of type `a`. --- | --- | Where [`Apply`](#apply) provides the ability to lift functions of two or --- | more arguments to functions whose arguments are wrapped using `f`, and --- | [`Functor`](#functor) provides the ability to lift functions of one --- | argument, `pure` can be seen as the function which lifts functions of --- | _zero_ arguments. That is, `Applicative` functors support a lifting --- | operation for any number of function arguments. --- | --- | Instances must satisfy the following laws in addition to the `Apply` --- | laws: --- | --- | - Identity: `(pure id) <*> v = v` --- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)` --- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)` --- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u` -class (Apply f) <= Applicative f where - pure :: forall a. a -> f a - -instance applicativeFn :: Applicative ((->) r) where - pure = const - -instance applicativeArray :: Applicative Array where - pure x = [x] - --- | `return` is an alias for `pure`. -return :: forall m a. (Applicative m) => a -> m a -return = pure - --- | `liftA1` provides a default implementation of `(<$>)` for any --- | [`Applicative`](#applicative) functor, without using `(<$>)` as provided --- | by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass --- | relationship. --- | --- | `liftA1` can therefore be used to write [`Functor`](#functor) instances --- | as follows: --- | --- | ```purescript --- | instance functorF :: Functor F where --- | map = liftA1 --- | ``` -liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b -liftA1 f a = pure f <*> a - --- | The `Bind` type class extends the [`Apply`](#apply) type class with a --- | "bind" operation `(>>=)` which composes computations in sequence, using --- | the return value of one computation to determine the next computation. --- | --- | The `>>=` operator can also be expressed using `do` notation, as follows: --- | --- | ```purescript --- | x >>= f = do y <- x --- | f y --- | ``` --- | --- | where the function argument of `f` is given the name `y`. --- | --- | Instances must satisfy the following law in addition to the `Apply` --- | laws: --- | --- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)` --- | --- | Associativity tells us that we can regroup operations which use `do` --- | notation so that we can unambiguously write, for example: --- | --- | ```purescript --- | do x <- m1 --- | y <- m2 x --- | m3 x y --- | ``` -class (Apply m) <= Bind m where - bind :: forall a b. m a -> (a -> m b) -> m b - -instance bindFn :: Bind ((->) r) where - bind m f x = f (m x) x - -instance bindArray :: Bind Array where - bind = arrayBind - -foreign import arrayBind :: forall a b. Array a -> (a -> Array b) -> Array b - -infixl 1 >>= - --- | `(>>=)` is an alias for `bind`. -(>>=) :: forall m a b. (Bind m) => m a -> (a -> m b) -> m b -(>>=) = bind - --- | The `Monad` type class combines the operations of the `Bind` and --- | `Applicative` type classes. Therefore, `Monad` instances represent type --- | constructors which support sequential composition, and also lifting of --- | functions of arbitrary arity. --- | --- | Instances must satisfy the following laws in addition to the --- | `Applicative` and `Bind` laws: --- | --- | - Left Identity: `pure x >>= f = f x` --- | - Right Identity: `x >>= pure = x` -class (Applicative m, Bind m) <= Monad m - -instance monadFn :: Monad ((->) r) -instance monadArray :: Monad Array - --- | `liftM1` provides a default implementation of `(<$>)` for any --- | [`Monad`](#monad), without using `(<$>)` as provided by the --- | [`Functor`](#functor)-[`Monad`](#monad) superclass relationship. --- | --- | `liftM1` can therefore be used to write [`Functor`](#functor) instances --- | as follows: --- | --- | ```purescript --- | instance functorF :: Functor F where --- | map = liftM1 --- | ``` -liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b -liftM1 f a = do - a' <- a - return (f a') - --- | `ap` provides a default implementation of `(<*>)` for any --- | [`Monad`](#monad), without using `(<*>)` as provided by the --- | [`Apply`](#apply)-[`Monad`](#monad) superclass relationship. --- | --- | `ap` can therefore be used to write [`Apply`](#apply) instances as --- | follows: --- | --- | ```purescript --- | instance applyF :: Apply F where --- | apply = ap --- | ``` -ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b -ap f a = do - f' <- f - a' <- a - return (f' a') - --- | The `Semigroup` type class identifies an associative operation on a type. --- | --- | Instances are required to satisfy the following law: --- | --- | - Associativity: `(x <> y) <> z = x <> (y <> z)` --- | --- | One example of a `Semigroup` is `String`, with `(<>)` defined as string --- | concatenation. -class Semigroup a where - append :: a -> a -> a - -infixr 5 <> -infixr 5 ++ - --- | `(<>)` is an alias for `append`. -(<>) :: forall s. (Semigroup s) => s -> s -> s -(<>) = append - --- | `(++)` is an alternative alias for `append`. -(++) :: forall s. (Semigroup s) => s -> s -> s -(++) = append - -instance semigroupString :: Semigroup String where - append = concatString - -instance semigroupUnit :: Semigroup Unit where - append _ _ = unit - -instance semigroupFn :: (Semigroup s') => Semigroup (s -> s') where - append f g = \x -> f x <> g x - -instance semigroupOrdering :: Semigroup Ordering where - append LT _ = LT - append GT _ = GT - append EQ y = y - -instance semigroupArray :: Semigroup (Array a) where - append = concatArray - -foreign import concatString :: String -> String -> String -foreign import concatArray :: forall a. Array a -> Array a -> Array a - --- | The `Semiring` class is for types that support an addition and --- | multiplication operation. --- | --- | Instances must satisfy the following laws: --- | --- | - Commutative monoid under addition: --- | - Associativity: `(a + b) + c = a + (b + c)` --- | - Identity: `zero + a = a + zero = a` --- | - Commutative: `a + b = b + a` --- | - Monoid under multiplication: --- | - Associativity: `(a * b) * c = a * (b * c)` --- | - Identity: `one * a = a * one = a` --- | - Multiplication distributes over addition: --- | - Left distributivity: `a * (b + c) = (a * b) + (a * c)` --- | - Right distributivity: `(a + b) * c = (a * c) + (b * c)` --- | - Annihiliation: `zero * a = a * zero = zero` -class Semiring a where - add :: a -> a -> a - zero :: a - mul :: a -> a -> a - one :: a - -instance semiringInt :: Semiring Int where - add = intAdd - zero = 0 - mul = intMul - one = 1 - -instance semiringNumber :: Semiring Number where - add = numAdd - zero = 0.0 - mul = numMul - one = 1.0 - -instance semiringUnit :: Semiring Unit where - add _ _ = unit - zero = unit - mul _ _ = unit - one = unit - -infixl 6 + -infixl 7 * - --- | `(+)` is an alias for `add`. -(+) :: forall a. (Semiring a) => a -> a -> a -(+) = add - --- | `(*)` is an alias for `mul`. -(*) :: forall a. (Semiring a) => a -> a -> a -(*) = mul - -foreign import intAdd :: Int -> Int -> Int -foreign import intMul :: Int -> Int -> Int -foreign import numAdd :: Number -> Number -> Number -foreign import numMul :: Number -> Number -> Number - --- | The `Ring` class is for types that support addition, multiplication, --- | and subtraction operations. --- | --- | Instances must satisfy the following law in addition to the `Semiring` --- | laws: --- | --- | - Additive inverse: `a - a = (zero - a) + a = zero` -class (Semiring a) <= Ring a where - sub :: a -> a -> a - -instance ringInt :: Ring Int where - sub = intSub - -instance ringNumber :: Ring Number where - sub = numSub - -instance ringUnit :: Ring Unit where - sub _ _ = unit - -infixl 6 - - --- | `(-)` is an alias for `sub`. -(-) :: forall a. (Ring a) => a -> a -> a -(-) = sub - --- | `negate x` can be used as a shorthand for `zero - x`. -negate :: forall a. (Ring a) => a -> a -negate a = zero - a - -foreign import intSub :: Int -> Int -> Int -foreign import numSub :: Number -> Number -> Number - --- | The `ModuloSemiring` class is for types that support addition, --- | multiplication, division, and modulo (division remainder) operations. --- | --- | Instances must satisfy the following law in addition to the `Semiring` --- | laws: --- | --- | - Remainder: ``a / b * b + (a `mod` b) = a`` -class (Semiring a) <= ModuloSemiring a where - div :: a -> a -> a - mod :: a -> a -> a - -instance moduloSemiringInt :: ModuloSemiring Int where - div = intDiv - mod = intMod - -instance moduloSemiringNumber :: ModuloSemiring Number where - div = numDiv - mod _ _ = 0.0 - -instance moduloSemiringUnit :: ModuloSemiring Unit where - div _ _ = unit - mod _ _ = unit - -infixl 7 / - --- | `(/)` is an alias for `div`. -(/) :: forall a. (ModuloSemiring a) => a -> a -> a -(/) = div - -foreign import intDiv :: Int -> Int -> Int -foreign import numDiv :: Number -> Number -> Number -foreign import intMod :: Int -> Int -> Int - --- | A `Ring` where every nonzero element has a multiplicative inverse. --- | --- | Instances must satisfy the following law in addition to the `Ring` and --- | `ModuloSemiring` laws: --- | --- | - Multiplicative inverse: `(one / x) * x = one` --- | --- | As a consequence of this ```a `mod` b = zero``` as no divide operation --- | will have a remainder. -class (Ring a, ModuloSemiring a) <= DivisionRing a - -instance divisionRingNumber :: DivisionRing Number -instance divisionRingUnit :: DivisionRing Unit - --- | The `Num` class is for types that are commutative fields. --- | --- | Instances must satisfy the following law in addition to the --- | `DivisionRing` laws: --- | --- | - Commutative multiplication: `a * b = b * a` -class (DivisionRing a) <= Num a - -instance numNumber :: Num Number -instance numUnit :: Num Unit - --- | The `Eq` type class represents types which support decidable equality. --- | --- | `Eq` instances should satisfy the following laws: --- | --- | - Reflexivity: `x == x = true` --- | - Symmetry: `x == y = y == x` --- | - Transitivity: if `x == y` and `y == z` then `x == z` -class Eq a where - eq :: a -> a -> Boolean - -infix 4 == -infix 4 /= - --- | `(==)` is an alias for `eq`. Tests whether one value is equal to another. -(==) :: forall a. (Eq a) => a -> a -> Boolean -(==) = eq - --- | `(/=)` tests whether one value is _not equal_ to another. Shorthand for --- | `not (x == y)`. -(/=) :: forall a. (Eq a) => a -> a -> Boolean -(/=) x y = not (x == y) - -instance eqBoolean :: Eq Boolean where - eq = refEq - -instance eqInt :: Eq Int where - eq = refEq - -instance eqNumber :: Eq Number where - eq = refEq - -instance eqChar :: Eq Char where - eq = refEq - -instance eqString :: Eq String where - eq = refEq - -instance eqUnit :: Eq Unit where - eq _ _ = true - -instance eqArray :: (Eq a) => Eq (Array a) where - eq = eqArrayImpl (==) - -instance eqOrdering :: Eq Ordering where - eq LT LT = true - eq GT GT = true - eq EQ EQ = true - eq _ _ = false - -foreign import refEq :: forall a. a -> a -> Boolean -foreign import refIneq :: forall a. a -> a -> Boolean -foreign import eqArrayImpl :: forall a. (a -> a -> Boolean) -> Array a -> Array a -> Boolean - --- | The `Ordering` data type represents the three possible outcomes of --- | comparing two values: --- | --- | `LT` - The first value is _less than_ the second. --- | `GT` - The first value is _greater than_ the second. --- | `EQ` - The first value is _equal to_ the second. -data Ordering = LT | GT | EQ - --- | The `Ord` type class represents types which support comparisons with a --- | _total order_. --- | --- | `Ord` instances should satisfy the laws of total orderings: --- | --- | - Reflexivity: `a <= a` --- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b` --- | - Transitivity: if `a <= b` and `b <= c` then `a <= c` -class (Eq a) <= Ord a where - compare :: a -> a -> Ordering - -instance ordBoolean :: Ord Boolean where - compare = unsafeCompare - -instance ordInt :: Ord Int where - compare = unsafeCompare - -instance ordNumber :: Ord Number where - compare = unsafeCompare - -instance ordString :: Ord String where - compare = unsafeCompare - -instance ordChar :: Ord Char where - compare = unsafeCompare - -instance ordUnit :: Ord Unit where - compare _ _ = EQ - -instance ordArray :: (Ord a) => Ord (Array a) where - compare xs ys = compare 0 $ ordArrayImpl (\x y -> case compare x y of - EQ -> 0 - LT -> 1 - GT -> -1) xs ys - -foreign import ordArrayImpl :: forall a. (a -> a -> Int) -> Array a -> Array a -> Int - -instance ordOrdering :: Ord Ordering where - compare LT LT = EQ - compare EQ EQ = EQ - compare GT GT = EQ - compare LT _ = LT - compare EQ LT = GT - compare EQ GT = LT - compare GT _ = GT - -infixl 4 < -infixl 4 > -infixl 4 <= -infixl 4 >= - --- | Test whether one value is _strictly less than_ another. -(<) :: forall a. (Ord a) => a -> a -> Boolean -(<) a1 a2 = case a1 `compare` a2 of - LT -> true - _ -> false - --- | Test whether one value is _strictly greater than_ another. -(>) :: forall a. (Ord a) => a -> a -> Boolean -(>) a1 a2 = case a1 `compare` a2 of - GT -> true - _ -> false - --- | Test whether one value is _non-strictly less than_ another. -(<=) :: forall a. (Ord a) => a -> a -> Boolean -(<=) a1 a2 = case a1 `compare` a2 of - GT -> false - _ -> true - --- | Test whether one value is _non-strictly greater than_ another. -(>=) :: forall a. (Ord a) => a -> a -> Boolean -(>=) a1 a2 = case a1 `compare` a2 of - LT -> false - _ -> true - -unsafeCompare :: forall a. a -> a -> Ordering -unsafeCompare = unsafeCompareImpl LT EQ GT - -foreign import unsafeCompareImpl :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering - --- | The `Bounded` type class represents types that are finite. --- | --- | Although there are no "internal" laws for `Bounded`, every value of `a` --- | should be considered less than or equal to `top` by some means, and greater --- | than or equal to `bottom`. --- | --- | The lack of explicit `Ord` constraint allows flexibility in the use of --- | `Bounded` so it can apply to total and partially ordered sets, boolean --- | algebras, etc. -class Bounded a where - top :: a - bottom :: a - -instance boundedBoolean :: Bounded Boolean where - top = true - bottom = false - -instance boundedUnit :: Bounded Unit where - top = unit - bottom = unit - -instance boundedOrdering :: Bounded Ordering where - top = GT - bottom = LT - -instance boundedInt :: Bounded Int where - top = topInt - bottom = bottomInt - --- | Characters fall within the Unicode range. -instance boundedChar :: Bounded Char where - top = topChar - bottom = bottomChar - -instance boundedFn :: (Bounded b) => Bounded (a -> b) where - top _ = top - bottom _ = bottom - -foreign import topInt :: Int -foreign import bottomInt :: Int - -foreign import topChar :: Char -foreign import bottomChar :: Char - --- | The `BoundedOrd` type class represents totally ordered finite data types. --- | --- | Instances should satisfy the following law in addition to the `Ord` laws: --- | --- | - Ordering: `bottom <= a <= top` -class (Bounded a, Ord a) <= BoundedOrd a - -instance boundedOrdBoolean :: BoundedOrd Boolean where -instance boundedOrdUnit :: BoundedOrd Unit where -instance boundedOrdOrdering :: BoundedOrd Ordering where -instance boundedOrdInt :: BoundedOrd Int where -instance boundedOrdChar :: BoundedOrd Char where - --- | The `BooleanAlgebra` type class represents types that behave like boolean --- | values. --- | --- | Instances should satisfy the following laws in addition to the `Bounded` --- | laws: --- | --- | - Associativity: --- | - `a || (b || c) = (a || b) || c` --- | - `a && (b && c) = (a && b) && c` --- | - Commutativity: --- | - `a || b = b || a` --- | - `a && b = b && a` --- | - Distributivity: --- | - `a && (b || c) = (a && b) || (a && c)` --- | - `a || (b && c) = (a || b) && (a || c)` --- | - Identity: --- | - `a || bottom = a` --- | - `a && top = a` --- | - Idempotent: --- | - `a || a = a` --- | - `a && a = a` --- | - Absorption: --- | - `a || (a && b) = a` --- | - `a && (a || b) = a` --- | - Annhiliation: --- | - `a || top = top` --- | - Complementation: --- | - `a && not a = bottom` --- | - `a || not a = top` -class (Bounded a) <= BooleanAlgebra a where - conj :: a -> a -> a - disj :: a -> a -> a - not :: a -> a - -instance booleanAlgebraBoolean :: BooleanAlgebra Boolean where - conj = boolAnd - disj = boolOr - not = boolNot - -instance booleanAlgebraUnit :: BooleanAlgebra Unit where - conj _ _ = unit - disj _ _ = unit - not _ = unit - -instance booleanAlgebraFn :: (BooleanAlgebra b) => BooleanAlgebra (a -> b) where - conj fx fy a = fx a `conj` fy a - disj fx fy a = fx a `disj` fy a - not fx a = not (fx a) - -infixr 3 && -infixr 2 || - --- | `(&&)` is an alias for `conj`. -(&&) :: forall a. (BooleanAlgebra a) => a -> a -> a -(&&) = conj - --- | `(||)` is an alias for `disj`. -(||) :: forall a. (BooleanAlgebra a) => a -> a -> a -(||) = disj - -foreign import boolOr :: Boolean -> Boolean -> Boolean -foreign import boolAnd :: Boolean -> Boolean -> Boolean -foreign import boolNot :: Boolean -> Boolean - --- | The `Show` type class represents those types which can be converted into --- | a human-readable `String` representation. --- | --- | While not required, it is recommended that for any expression `x`, the --- | string `show x` be executable PureScript code which evaluates to the same --- | value as the expression `x`. -class Show a where - show :: a -> String - -instance showBoolean :: Show Boolean where - show true = "true" - show false = "false" - -instance showInt :: Show Int where - show = showIntImpl - -instance showNumber :: Show Number where - show = showNumberImpl - -instance showChar :: Show Char where - show = showCharImpl - -instance showString :: Show String where - show = showStringImpl - -instance showUnit :: Show Unit where - show _ = "unit" - -instance showArray :: (Show a) => Show (Array a) where - show = showArrayImpl show - -instance showOrdering :: Show Ordering where - show LT = "LT" - show GT = "GT" - show EQ = "EQ" - -foreign import showIntImpl :: Int -> String -foreign import showNumberImpl :: Number -> String -foreign import showCharImpl :: Char -> String -foreign import showStringImpl :: String -> String -foreign import showArrayImpl :: forall a. (a -> String) -> Array a -> String +import Control.Applicative (class Applicative, pure, liftA1, unless, when) +import Control.Apply (class Apply, apply, (*>), (<*), (<*>)) +import Control.Bind (class Bind, bind, ifM, join, (<=<), (=<<), (>=>), (>>=)) +import Control.Category (class Category, id) +import Control.Monad (class Monad, ap, liftM1) +import Control.Semigroupoid (class Semigroupoid, compose, (<<<), (>>>)) + +import Data.Boolean (otherwise) +import Data.BooleanAlgebra (class BooleanAlgebra) +import Data.Bounded (class Bounded, bottom, top) +import Data.CommutativeRing (class CommutativeRing) +import Data.Eq (class Eq, eq, notEq, (/=), (==)) +import Data.EuclideanRing (class EuclideanRing, degree, div, mod, (/)) +import Data.Field (class Field) +import Data.Function (const, flip, ($), (#)) +import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>)) +import Data.HeytingAlgebra (class HeytingAlgebra, conj, disj, not, (&&), (||)) +import Data.Ord (class Ord, compare, (<), (<=), (>), (>=), comparing, min, max, clamp, between) +import Data.Ordering (Ordering(..)) +import Data.Ring (class Ring, negate, sub, (-)) +import Data.Semigroup (class Semigroup, append, (<>)) +import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+)) +import Data.Show (class Show, show) +import Data.Unit (Unit, unit) +import Data.Void (Void, absurd) diff --git a/tests/support/flattened/Test-Assert.js b/tests/support/flattened/Test-Assert.js index ad1a67ca49..31d8a1eff8 100644 --- a/tests/support/flattened/Test-Assert.js +++ b/tests/support/flattened/Test-Assert.js @@ -1,4 +1,3 @@ -/* global exports */ "use strict"; // module Test.Assert diff --git a/tests/support/flattened/Test-Assert.purs b/tests/support/flattened/Test-Assert.purs index 66b8622158..23e6b48c94 100644 --- a/tests/support/flattened/Test-Assert.purs +++ b/tests/support/flattened/Test-Assert.purs @@ -1,13 +1,14 @@ module Test.Assert - ( assert' + ( ASSERT , assert + , assert' , assertThrows , assertThrows' - , ASSERT() ) where -import Control.Monad.Eff (Eff()) -import Prelude +import Control.Monad.Eff (Eff) +import Control.Monad ((=<<)) +import Data.Unit (Unit) -- | Assertion effect type. foreign import data ASSERT :: ! @@ -19,7 +20,11 @@ assert = assert' "Assertion failed" -- | Throws a runtime exception with the specified message when the boolean -- | value is false. -foreign import assert' :: forall e. String -> Boolean -> Eff (assert :: ASSERT | e) Unit +foreign import assert' + :: forall e + . String + -> Boolean + -> Eff (assert :: ASSERT | e) Unit -- | Throws a runtime exception with message "Assertion failed: An error should -- | have been thrown", unless the argument throws an exception when evaluated. @@ -29,7 +34,8 @@ foreign import assert' :: forall e. String -> Boolean -> Eff (assert :: ASSERT | -- | satisfied. Functions which use `Eff (err :: EXCEPTION | eff) a` can be -- | tested with `catchException` instead. assertThrows :: forall e a. (Unit -> a) -> Eff (assert :: ASSERT | e) Unit -assertThrows = assertThrows' "Assertion failed: An error should have been thrown" +assertThrows = + assertThrows' "Assertion failed: An error should have been thrown" -- | Throws a runtime exception with the specified message, unless the argument -- | throws an exception when evaluated. @@ -38,9 +44,14 @@ assertThrows = assertThrows' "Assertion failed: An error should have been thrown -- | to make sure that an exception is thrown if a precondition is not -- | satisfied. Functions which use `Eff (err :: EXCEPTION | eff) a` can be -- | tested with `catchException` instead. -assertThrows' :: forall e a. String -> (Unit -> a) -> Eff (assert :: ASSERT | e) Unit -assertThrows' msg fn = - checkThrows fn >>= assert' msg - - -foreign import checkThrows :: forall e a. (Unit -> a) -> Eff (assert :: ASSERT | e) Boolean +assertThrows' + :: forall e a + . String + -> (Unit -> a) + -> Eff (assert :: ASSERT | e) Unit +assertThrows' msg fn = assert' msg =<< checkThrows fn + +foreign import checkThrows + :: forall e a + . (Unit -> a) + -> Eff (assert :: ASSERT | e) Boolean diff --git a/tests/support/prelude b/tests/support/prelude index 5b8da18fd7..4033348219 160000 --- a/tests/support/prelude +++ b/tests/support/prelude @@ -1 +1 @@ -Subproject commit 5b8da18fd7b8d57a85df49ec64099a81b13f42f7 +Subproject commit 403334821953d50fb6eae4b40efd1e542e3e47de From 27c99c6f0b0c5a9f2e4e5001533fc065d3308305 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Fri, 25 Mar 2016 15:44:35 +0000 Subject: [PATCH 2/2] Disable psci tests that rely on re-exports --- tests/TestPsci.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/TestPsci.hs b/tests/TestPsci.hs index a3c08008ab..31f7384512 100644 --- a/tests/TestPsci.hs +++ b/tests/TestPsci.hs @@ -76,12 +76,12 @@ completionTestData = -- :type should complete values and data constructors in scope , (":type Control.Monad.Eff.Console.lo", [":type Control.Monad.Eff.Console.log", ":type Control.Monad.Eff.Console.logShow"]) - , (":type uni", [":type unit"]) - , (":type E", [":type EQ"]) + --, (":type uni", [":type unit"]) + --, (":type E", [":type EQ"]) -- :kind should complete types in scope - , (":kind C", [":kind Control.Monad.Eff.Pure"]) - , (":kind O", [":kind Ordering"]) + --, (":kind C", [":kind Control.Monad.Eff.Pure"]) + --, (":kind O", [":kind Ordering"]) -- Only one argument for directives should be completed , (":show import ", []) @@ -99,9 +99,9 @@ completionTestData = , ("34", []) -- Identifiers and data constructors should be completed - , ("uni", ["unit"]) + --, ("uni", ["unit"]) , ("Control.Monad.Eff.Class.", ["Control.Monad.Eff.Class.liftEff"]) - , ("G", ["GT"]) + --, ("G", ["GT"]) , ("Data.Ordering.L", ["Data.Ordering.LT"]) -- if a module is imported qualified, values should complete under the