@@ -234,7 +234,7 @@ module Prelude
234 class Functor f where
234 class Functor f where
235 (<$>) :: forall a b. (a -> b) -> f a -> f b
235 (<$>) :: forall a b. (a -> b) -> f a -> f b
237− -- | `(<#>)` is `(<$>)` with its arguments flipped. For example:
237+ -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
239 -- | ```purescript
239 -- | ```purescript
240 -- | [1, 2, 3] <#> \n -> n * n
240 -- | [1, 2, 3] <#> \n -> n * n
@@ -866,21 +866,51 @@ module Prelude
867module Data.Function where
867module Data.Function where
869+ -- | The `on` function is used to change the domain of a binary operator.
871+ -- | For example, we can create a function which compares two records based on the values of their `x` properties:
874+ -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
875+ -- | compareX = compare `on` _.x
869 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
877 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
870 on f g x y = g x `f` g y
878 on f g x y = g x `f` g y
880+ -- | A function of zero arguments
872 foreign import data Fn0 :: * -> *
881 foreign import data Fn0 :: * -> *
883+ -- | A function of one argument
873 foreign import data Fn1 :: * -> * -> *
884 foreign import data Fn1 :: * -> * -> *
886+ -- | A function of two arguments
874 foreign import data Fn2 :: * -> * -> * -> *
887 foreign import data Fn2 :: * -> * -> * -> *
889+ -- | A function of three arguments
875 foreign import data Fn3 :: * -> * -> * -> * -> *
890 foreign import data Fn3 :: * -> * -> * -> * -> *
892+ -- | A function of four arguments
876 foreign import data Fn4 :: * -> * -> * -> * -> * -> *
893 foreign import data Fn4 :: * -> * -> * -> * -> * -> *
895+ -- | A function of five arguments
877 foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
896 foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
898+ -- | A function of six arguments
878 foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
899 foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
901+ -- | A function of seven arguments
879 foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
902 foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
904+ -- | A function of eight arguments
880 foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
905 foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
907+ -- | A function of nine arguments
881 foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
908 foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
910+ -- | A function of ten arguments
882 foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
911 foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
913+ -- | Create a function of no arguments
884 foreign import mkFn0
914 foreign import mkFn0
886 function mkFn0(fn) {
916 function mkFn0(fn) {
@@ -890,6 +920,7 @@ module Data.Function where
891 """ :: forall a. (Unit -> a) -> Fn0 a
921 """ :: forall a. (Unit -> a) -> Fn0 a
923+ -- | Create a function of one argument
893 foreign import mkFn1
924 foreign import mkFn1
895 function mkFn1(fn) {
926 function mkFn1(fn) {
@@ -899,6 +930,7 @@ module Data.Function where
900 """ :: forall a b. (a -> b) -> Fn1 a b
931 """ :: forall a b. (a -> b) -> Fn1 a b
933+ -- | Create a function of two arguments from a curried function
902 foreign import mkFn2
934 foreign import mkFn2
904 function mkFn2(fn) {
936 function mkFn2(fn) {
@@ -908,6 +940,7 @@ module Data.Function where
909 """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
941 """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
943+ -- | Create a function of three arguments from a curried function
911 foreign import mkFn3
944 foreign import mkFn3
913 function mkFn3(fn) {
946 function mkFn3(fn) {
@@ -917,6 +950,7 @@ module Data.Function where
918 """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
951 """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
953+ -- | Create a function of four arguments from a curried function
920 foreign import mkFn4
954 foreign import mkFn4
922 function mkFn4(fn) {
956 function mkFn4(fn) {
@@ -926,6 +960,7 @@ module Data.Function where
927 """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
961 """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
963+ -- | Create a function of five arguments from a curried function
929 foreign import mkFn5
964 foreign import mkFn5
931 function mkFn5(fn) {
966 function mkFn5(fn) {
@@ -935,6 +970,7 @@ module Data.Function where
936 """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
971 """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
973+ -- | Create a function of six arguments from a curried function
938 foreign import mkFn6
974 foreign import mkFn6
940 function mkFn6(fn) {
976 function mkFn6(fn) {
@@ -944,6 +980,7 @@ module Data.Function where
945 """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
981 """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
983+ -- | Create a function of seven arguments from a curried function
947 foreign import mkFn7
984 foreign import mkFn7
949 function mkFn7(fn) {
986 function mkFn7(fn) {
@@ -953,6 +990,7 @@ module Data.Function where
954 """ :: 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
991 """ :: 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
993+ -- | Create a function of eight arguments from a curried function
956 foreign import mkFn8
994 foreign import mkFn8
958 function mkFn8(fn) {
996 function mkFn8(fn) {
@@ -962,6 +1000,7 @@ module Data.Function where
963 """ :: 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
1001 """ :: 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
1003+ -- | Create a function of nine arguments from a curried function
965 foreign import mkFn9
1004 foreign import mkFn9
967 function mkFn9(fn) {
1006 function mkFn9(fn) {
@@ -971,6 +1010,7 @@ module Data.Function where
972 """ :: 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
1011 """ :: 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
1013+ -- | Create a function of ten arguments from a curried function
974 foreign import mkFn10
1014 foreign import mkFn10
976 function mkFn10(fn) {
1016 function mkFn10(fn) {
@@ -980,6 +1020,7 @@ module Data.Function where
981 """ :: 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
1021 """ :: 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
1023+ -- | Apply a function of no arguments
983 foreign import runFn0
1024 foreign import runFn0
985 function runFn0(fn) {
1026 function runFn0(fn) {
@@ -987,6 +1028,7 @@ module Data.Function where
988 """ :: forall a. Fn0 a -> a
1029 """ :: forall a. Fn0 a -> a
1031+ -- | Apply a function of one argument
990 foreign import runFn1
1032 foreign import runFn1
992 function runFn1(fn) {
1034 function runFn1(fn) {
@@ -996,6 +1038,7 @@ module Data.Function where
997 """ :: forall a b. Fn1 a b -> a -> b
1039 """ :: forall a b. Fn1 a b -> a -> b
1041+ -- | Apply a function of two arguments
999 foreign import runFn2
1042 foreign import runFn2
1001 function runFn2(fn) {
1044 function runFn2(fn) {
@@ -1007,6 +1050,7 @@ module Data.Function where
1008 """ :: forall a b c. Fn2 a b c -> a -> b -> c
1051 """ :: forall a b c. Fn2 a b c -> a -> b -> c
1053+ -- | Apply a function of three arguments
1010 foreign import runFn3
1054 foreign import runFn3
1012 function runFn3(fn) {
1056 function runFn3(fn) {
@@ -1020,6 +1064,7 @@ module Data.Function where
1021 """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1065 """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1067+ -- | Apply a function of four arguments
1023 foreign import runFn4
1068 foreign import runFn4
1025 function runFn4(fn) {
1070 function runFn4(fn) {
@@ -1035,6 +1080,7 @@ module Data.Function where
1036 """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1081 """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1083+ -- | Apply a function of five arguments
1038 foreign import runFn5
1084 foreign import runFn5
1040 function runFn5(fn) {
1086 function runFn5(fn) {
@@ -1052,6 +1098,7 @@ module Data.Function where
1053 """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1099 """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1101+ -- | Apply a function of six arguments
1055 foreign import runFn6
1102 foreign import runFn6
1057 function runFn6(fn) {
1104 function runFn6(fn) {
@@ -1071,6 +1118,7 @@ module Data.Function where
1072 """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1119 """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1121+ -- | Apply a function of seven arguments
1074 foreign import runFn7
1122 foreign import runFn7
1076 function runFn7(fn) {
1124 function runFn7(fn) {
@@ -1092,6 +1140,7 @@ module Data.Function where
1093 """ :: 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
1141 """ :: 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
1143+ -- | Apply a function of eight arguments
1095 foreign import runFn8
1144 foreign import runFn8
1097 function runFn8(fn) {
1146 function runFn8(fn) {
@@ -1115,6 +1164,7 @@ module Data.Function where
1116 """ :: 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
1165 """ :: 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
1167+ -- | Apply a function of nine arguments
1118 foreign import runFn9
1168 foreign import runFn9
1120 function runFn9(fn) {
1170 function runFn9(fn) {
@@ -1140,6 +1190,7 @@ module Data.Function where
1141 """ :: 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
1191 """ :: 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
1193+ -- | Apply a function of ten arguments
1143 foreign import runFn10
1194 foreign import runFn10
1145 function runFn10(fn) {
1196 function runFn10(fn) {
@@ -1169,6 +1220,9 @@ module Data.Function where
1170module Prelude.Unsafe where
1221module Prelude.Unsafe where
1223+ -- | Find the element of an array at the specified index.
1225+ -- | Note: this function can cause unpredictable failure at runtime if the index is out-of-bounds.
1172 foreign import unsafeIndex
1226 foreign import unsafeIndex
1174 function unsafeIndex(xs) {
1228 function unsafeIndex(xs) {
@@ -1178,8 +1232,18 @@ module Prelude.Unsafe where
1179 """ :: forall a. [a] -> Number -> a
1233 """ :: forall a. [a] -> Number -> a
1181−module Control.Monad.Eff where
1235+module Control.Monad.Eff
1239+ , untilE, whileE, forE, foreachE
1242+ -- | The `Eff` type constructor is used to represent _native_ effects.
1244+ -- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
1246+ -- | 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.
1183 foreign import data Eff :: # ! -> * -> *
1247 foreign import data Eff :: # ! -> * -> *
1185 foreign import returnE
1249 foreign import returnE
@@ -1202,8 +1266,15 @@ module Control.Monad.Eff where
1203 """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1267 """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1269+ -- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
1271+ -- | The `runPure` function can be used to run pure computations and obtain their result.
1205 type Pure a = forall e. Eff e a
1272 type Pure a = forall e. Eff e a
1274+ -- | Run a pure computation and return its result.
1276+ -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1277+ -- | is to use parentheses instead.
1207 foreign import runPure
1278 foreign import runPure
1209 function runPure(f) {
1280 function runPure(f) {
@@ -1225,6 +1296,10 @@ module Control.Monad.Eff where
1226 instance monadEff :: Monad (Eff e)
1297 instance monadEff :: Monad (Eff e)
1299+ -- | Loop until a condition becomes `true`.
1301+ -- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1302+ -- | until its return value is `true`.
1228 foreign import untilE
1303 foreign import untilE
1230 function untilE(f) {
1305 function untilE(f) {
@@ -1235,6 +1310,10 @@ module Control.Monad.Eff where
1236 """ :: forall e. Eff e Boolean -> Eff e Unit
1311 """ :: forall e. Eff e Boolean -> Eff e Unit
1313+ -- | Loop while a condition is `true`.
1315+ -- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1316+ -- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1238 foreign import whileE
1317 foreign import whileE
1240 function whileE(f) {
1319 function whileE(f) {
@@ -1249,6 +1328,10 @@ module Control.Monad.Eff where
1250 """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1329 """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1331+ -- | Loop over a consecutive collection of numbers.
1333+ -- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
1334+ -- | between `lo` (inclusive) and `hi` (exclusive).
1252 foreign import forE
1335 foreign import forE
1254 function forE(lo) {
1337 function forE(lo) {
@@ -1264,7 +1347,9 @@ module Control.Monad.Eff where
1265 """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1348 """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1267−
1350+ -- | Loop over an array of values.
1352+ -- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
1268 foreign import foreachE
1353 foreign import foreachE
1270 function foreachE(as) {
1355 function foreachE(as) {
@@ -1282,6 +1367,9 @@ module Control.Monad.Eff.Unsafe where
1283 import Control.Monad.Eff
1368 import Control.Monad.Eff
1370+ -- | Change the type of an effectful computation, allowing it to be run in another context.
1372+ -- | Note: use of this function can result in arbitrary side-effects.
1285 foreign import unsafeInterleaveEff
1373 foreign import unsafeInterleaveEff
1287 function unsafeInterleaveEff(f) {
1375 function unsafeInterleaveEff(f) {
@@ -1293,8 +1381,10 @@ module Debug.Trace where
1294 import Control.Monad.Eff
1382 import Control.Monad.Eff
1384+ -- | The `Trace` effect represents those computations which write to the console.
1296 foreign import data Trace :: !
1385 foreign import data Trace :: !
1387+ -- | Write a `String` to the console.
1298 foreign import trace
1388 foreign import trace
1300 function trace(s) {
1390 function trace(s) {
@@ -1305,6 +1395,7 @@ module Debug.Trace where
1306 """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1396 """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1398+ -- | Write a value to the console, using its `Show` instance to produce a `String`.
1308 print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1399 print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1309 print o = trace (show o)
1400 print o = trace (show o)
@@ -1312,10 +1403,17 @@ module Control.Monad.ST where
1313 import Control.Monad.Eff
1404 import Control.Monad.Eff
1406+ -- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
1408+ -- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
1410+ -- | The `runST` function can be used to handle the `ST` effect.
1315 foreign import data ST :: * -> !
1411 foreign import data ST :: * -> !
1413+ -- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
1317 foreign import data STRef :: * -> * -> *
1414 foreign import data STRef :: * -> * -> *
1416+ -- | Create a new mutable reference.
1319 foreign import newSTRef
1417 foreign import newSTRef
1321 function newSTRef(val) {
1419 function newSTRef(val) {
@@ -1325,6 +1423,7 @@ module Control.Monad.ST where
1326 """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1424 """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1426+ -- | Read the current value of a mutable reference.
1328 foreign import readSTRef
1427 foreign import readSTRef
1330 function readSTRef(ref) {
1429 function readSTRef(ref) {
@@ -1334,6 +1433,7 @@ module Control.Monad.ST where
1335 """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1434 """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1436+ -- | Modify the value of a mutable reference by applying a function to the current value.
1337 foreign import modifySTRef
1437 foreign import modifySTRef
1339 function modifySTRef(ref) {
1439 function modifySTRef(ref) {
@@ -1345,6 +1445,7 @@ module Control.Monad.ST where
1346 """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1446 """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1448+ -- | Set the value of a mutable reference.
1348 foreign import writeSTRef
1449 foreign import writeSTRef
1350 function writeSTRef(ref) {
1451 function writeSTRef(ref) {
@@ -1356,6 +1457,12 @@ module Control.Monad.ST where
1357 """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1458 """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1460+ -- | Run an `ST` computation.
1462+ -- | 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
1463+ -- | to the surrounding computation.
1465+ -- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
1359 foreign import runST
1466 foreign import runST
1361 function runST(f) {
1468 function runST(f) {
@@ -1363,5 +1470,9 @@ module Control.Monad.ST where
1364 """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1471 """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1473+ -- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
1475+ -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1476+ -- | is to use parentheses instead.
1366 pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1477 pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1367 pureST st = runPure (runST st)
1478 pureST st = runPure (runST st)