Skip to content

Commit fa2c186

Browse files
committed
Updates for Arrays
1 parent f8423ff commit fa2c186

File tree

4 files changed

+14
-56
lines changed

4 files changed

+14
-56
lines changed

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)