Skip to content

Commit dc2996b

Browse files
committed
Add Alternative
1 parent 1c28012 commit dc2996b

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Module Documentation
22

3+
## Module Control.Alt
4+
5+
### Type Classes
6+
7+
class (Functor f) <= Alt f where
8+
(<|>) :: forall a. f a -> f a -> f a
9+
10+
11+
## Module Control.Alternative
12+
13+
### Type Classes
14+
15+
class (Applicative f, Plus f) <= Alternative f where
16+
17+
18+
### Values
19+
20+
many :: forall f a. (Alternative f) => f a -> f [a]
21+
22+
some :: forall f a. (Alternative f) => f a -> f [a]
23+
24+
325
## Module Control.Apply
426

527
### Values
@@ -44,4 +66,12 @@
4466

4567
unless :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
4668

47-
when :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
69+
when :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
70+
71+
72+
## Module Control.Plus
73+
74+
### Type Classes
75+
76+
class (Alt f) <= Plus f where
77+
empty :: forall a. f a

src/Control/Alt.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Control.Alt where
2+
3+
infixl 3 <|>
4+
5+
class (Functor f) <= Alt f where
6+
(<|>) :: forall a. f a -> f a -> f a

src/Control/Alternative.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Control.Alternative where
2+
3+
import Control.Alt
4+
import Control.Plus
5+
6+
class (Applicative f, Plus f) <= Alternative f
7+
8+
some :: forall f a. (Alternative f) => f a -> f [a]
9+
some v = (:) <$> v <*> many v
10+
11+
many :: forall f a. (Alternative f) => f a -> f [a]
12+
many v = some v <|> pure []

src/Control/Plus.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Control.Plus where
2+
3+
import Control.Alt
4+
5+
class (Alt f) <= Plus f where
6+
empty :: forall a. f a

0 commit comments

Comments
 (0)