Skip to content

Commit fb36762

Browse files
committed
Add Lazy
1 parent 5d5c21a commit fb36762

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
### Values
1919

20-
many :: forall f a. (Alternative f) => f a -> f [a]
20+
many :: forall f a. (Alternative f, Lazy1 f) => f a -> f [a]
2121

22-
some :: forall f a. (Alternative f) => f a -> f [a]
22+
some :: forall f a. (Alternative f, Lazy1 f) => f a -> f [a]
2323

2424

2525
## Module Control.Apply
@@ -56,6 +56,17 @@
5656
join :: forall a m. (Bind m) => m (m a) -> m a
5757

5858

59+
## Module Control.Lazy
60+
61+
### Type Classes
62+
63+
class Lazy a where
64+
defer :: (Unit -> a) -> a
65+
66+
class Lazy1 a where
67+
defer1 :: forall t. (Unit -> a t) -> a t
68+
69+
5970
## Module Control.Monad
6071

6172
### Values

src/Control/Alternative.purs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
module Control.Alternative where
22

33
import Control.Alt
4+
import Control.Lazy
45
import Control.Plus
56

67
class (Applicative f, Plus f) <= Alternative f
78

8-
some :: forall f a. (Alternative f) => f a -> f [a]
9-
some v = (:) <$> v <*> many v
9+
some :: forall f a. (Alternative f, Lazy1 f) => f a -> f [a]
10+
some v = (:) <$> v <*> defer1 (\_ -> many v)
1011

11-
many :: forall f a. (Alternative f) => f a -> f [a]
12+
many :: forall f a. (Alternative f, Lazy1 f) => f a -> f [a]
1213
many v = some v <|> pure []
14+

src/Control/Lazy.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Control.Lazy where
2+
3+
class Lazy a where
4+
defer :: (Unit -> a) -> a
5+
6+
class Lazy1 a where
7+
defer1 :: forall t. (Unit -> a t) -> a t

0 commit comments

Comments
 (0)