Skip to content

Commit f1bcb8f

Browse files
committed
Merge pull request #23 from purescript/0.7
Updates for Arrays
2 parents f8423ff + 230d7c1 commit f1bcb8f

9 files changed

+33
-121
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"purescript-integers": "~0.2.0"
19+
"purescript-prelude": "~0.1.0"
2020
}
2121
}

docs/Control.Alt.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This module defines the `Alt` type class.
99

1010
``` purescript
1111
class (Functor f) <= Alt f where
12-
(<|>) :: forall a. f a -> f a -> f a
12+
alt :: forall a. f a -> f a -> f a
1313
```
1414

1515
The `Alt` type class identifies an associative operation on a type
@@ -25,5 +25,13 @@ types of kind `* -> *`, like `Array` or `List`, rather than concrete types
2525
For example, the `Array` (`[]`) type is an instance of `Alt`, where
2626
`(<|>)` is defined to be concatenation.
2727

28+
#### `(<|>)`
29+
30+
``` purescript
31+
(<|>) :: forall f a. (Alt f) => f a -> f a -> f a
32+
```
33+
34+
An infix version of `alt`.
35+
2836

2937

docs/Control.Alternative.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,5 @@ laws:
2121
- Distributivity: `(f <|> g) <*> x == (f <*> x) <|> (g <*> x)`
2222
- Annihilation: `empty <*> f = empty`
2323

24-
#### `some`
25-
26-
``` purescript
27-
some :: forall f a. (Alternative f, Lazy (f [a])) => f a -> f [a]
28-
```
29-
30-
Attempt a computation multiple times, requiring at least one success.
31-
32-
The `Lazy` constraint is used to generate the result lazily, to ensure
33-
termination.
34-
35-
#### `many`
36-
37-
``` purescript
38-
many :: forall f a. (Alternative f, Lazy (f [a])) => f a -> f [a]
39-
```
40-
41-
Attempt a computation multiple times, returning as many successful results
42-
as possible (possibly zero).
43-
44-
The `Lazy` constraint is used to generate the result lazily, to ensure
45-
termination.
46-
4724

4825

docs/Control.Extend.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This module defines the `Extend` type class and associated helper functions.
99

1010
``` purescript
1111
class (Functor w) <= Extend w where
12-
(<<=) :: forall b a. (w a -> b) -> w a -> w b
12+
extend :: forall b a. (w a -> b) -> w a -> w b
1313
```
1414

1515
The `Extend` class defines the extension operator `(<<=)`
@@ -30,6 +30,14 @@ instance extendArr :: (Semigroup w) => Extend (Prim.Function w)
3030
```
3131

3232

33+
#### `(<<=)`
34+
35+
``` purescript
36+
(<<=) :: forall w a b. (Extend w) => (w a -> b) -> w a -> w b
37+
```
38+
39+
An infix version of `extend`
40+
3341
#### `(=>>)`
3442

3543
``` purescript
@@ -54,14 +62,6 @@ Forwards co-Kleisli composition.
5462

5563
Backwards co-Kleisli composition.
5664

57-
#### `extend`
58-
59-
``` purescript
60-
extend :: forall b a w. (Extend w) => (w a -> b) -> w a -> w b
61-
```
62-
63-
An alias for `(<<=)`.
64-
6565
#### `duplicate`
6666

6767
``` purescript

docs/Control.Monad.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,6 @@
55

66
This module defines helper functions for working with `Monad` instances.
77

8-
#### `replicateM`
9-
10-
``` purescript
11-
replicateM :: forall m a. (Monad m) => Int -> m a -> m [a]
12-
```
13-
14-
Perform a monadic action `n` times collecting all of the results.
15-
16-
#### `foldM`
17-
18-
``` purescript
19-
foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
20-
```
21-
22-
Perform a fold using a monadic step function.
23-
248
#### `when`
259

2610
``` purescript
@@ -37,20 +21,5 @@ unless :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
3721

3822
Perform a monadic action unless a condition is true.
3923

40-
#### `filterM`
41-
42-
``` purescript
43-
filterM :: forall a m. (Monad m) => (a -> m Boolean) -> [a] -> m [a]
44-
```
45-
46-
Filter where the predicate returns a monadic `Boolean`.
47-
48-
For example:
49-
50-
```purescript
51-
powerSet :: forall a. [a] -> [[a]]
52-
powerSet = filterM (const [true, false])
53-
```
54-
5524

5625

src/Control/Alt.purs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
module Control.Alt where
44

5-
infixl 3 <|>
6-
75
-- | The `Alt` type class identifies an associative operation on a type
86
-- | constructor. It is similar to `Semigroup`, except that it applies to
97
-- | types of kind `* -> *`, like `Array` or `List`, rather than concrete types
@@ -17,4 +15,10 @@ infixl 3 <|>
1715
-- | For example, the `Array` (`[]`) type is an instance of `Alt`, where
1816
-- | `(<|>)` is defined to be concatenation.
1917
class (Functor f) <= Alt f where
20-
(<|>) :: forall a. f a -> f a -> f a
18+
alt :: forall a. f a -> f a -> f a
19+
20+
infixl 3 <|>
21+
22+
-- | An infix version of `alt`.
23+
(<|>) :: forall f a. (Alt f) => f a -> f a -> f a
24+
(<|>) = alt

src/Control/Alternative.purs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,3 @@ import Control.Plus
1717
-- | - Annihilation: `empty <*> f = empty`
1818
class (Applicative f, Plus f) <= Alternative f
1919

20-
-- | Attempt a computation multiple times, requiring at least one success.
21-
-- |
22-
-- | The `Lazy` constraint is used to generate the result lazily, to ensure
23-
-- | termination.
24-
some :: forall f a. (Alternative f, Lazy (f [a])) => f a -> f [a]
25-
some v = (:) <$> v <*> defer (\_ -> many v)
26-
27-
-- | Attempt a computation multiple times, returning as many successful results
28-
-- | as possible (possibly zero).
29-
-- |
30-
-- | The `Lazy` constraint is used to generate the result lazily, to ensure
31-
-- | termination.
32-
many :: forall f a. (Alternative f, Lazy (f [a])) => f a -> f [a]
33-
many v = some v <|> pure []
34-

src/Control/Extend.purs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ infixr 1 =<=
1818
-- |
1919
-- | - Associativity: `extend f <<< extend g = extend (f <<< extend g)`
2020
class (Functor w) <= Extend w where
21-
(<<=) :: forall b a. (w a -> b) -> w a -> w b
21+
extend :: forall b a. (w a -> b) -> w a -> w b
2222

2323
instance extendArr :: (Semigroup w) => Extend ((->) w) where
24-
(<<=) f g w = f \w' -> g (w <> w')
24+
extend f g w = f \w' -> g (w <> w')
25+
26+
-- | An infix version of `extend`
27+
(<<=) :: forall w a b. (Extend w) => (w a -> b) -> w a -> w b
28+
(<<=) = extend
2529

2630
-- | A version of `(<<=)` with its arguments flipped.
2731
(=>>) :: forall b a w. (Extend w) => w a -> (w a -> b) -> w b
@@ -35,12 +39,8 @@ instance extendArr :: (Semigroup w) => Extend ((->) w) where
3539
(=<=) :: forall b a w c. (Extend w) => (w b -> c) -> (w a -> b) -> w a -> c
3640
(=<=) f g w = f (g <<= w)
3741

38-
-- | An alias for `(<<=)`.
39-
extend :: forall b a w. (Extend w) => (w a -> b) -> w a -> w b
40-
extend = (<<=)
41-
4242
-- | Duplicate a comonadic context.
4343
-- |
4444
-- | `duplicate` is dual to `Control.Bind.join`.
4545
duplicate :: forall a w. (Extend w) => w a -> w (w a)
46-
duplicate w = id <<= w
46+
duplicate = extend id

src/Control/Monad.purs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22

33
module Control.Monad where
44

5-
import Data.Int (Int())
6-
7-
-- | Perform a monadic action `n` times collecting all of the results.
8-
replicateM :: forall m a. (Monad m) => Int -> m a -> m [a]
9-
replicateM n m | n < one = return []
10-
| otherwise = do a <- m
11-
as <- replicateM (n - one) m
12-
return (a : as)
13-
14-
-- | Perform a fold using a monadic step function.
15-
foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
16-
foldM _ a [] = return a
17-
foldM f a (b:bs) = f a b >>= \a' -> foldM f a' bs
18-
195
-- | Perform a monadic action when a condition is true.
206
when :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
217
when true m = m
@@ -25,20 +11,3 @@ when false _ = return unit
2511
unless :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
2612
unless false m = m
2713
unless true _ = return unit
28-
29-
-- | Filter where the predicate returns a monadic `Boolean`.
30-
-- |
31-
-- | For example:
32-
-- |
33-
-- | ```purescript
34-
-- | powerSet :: forall a. [a] -> [[a]]
35-
-- | powerSet = filterM (const [true, false])
36-
-- | ```
37-
filterM :: forall a m. (Monad m) => (a -> m Boolean) -> [a] -> m [a]
38-
filterM _ [] = return []
39-
filterM p (x:xs) = do
40-
b <- p x
41-
xs' <- filterM p xs
42-
return $ if b
43-
then x : xs'
44-
else xs'

0 commit comments

Comments
 (0)