Skip to content

Commit 849032c

Browse files
committed
Add Lazy2, fix, fix1, fix2
1 parent e7662bf commit 849032c

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,23 @@
6060

6161
### Type Classes
6262

63-
class Lazy a where
64-
defer :: (Unit -> a) -> a
63+
class Lazy l where
64+
defer :: (Unit -> l) -> l
6565

66-
class Lazy1 a where
67-
defer1 :: forall b. (Unit -> a b) -> a b
66+
class Lazy1 l where
67+
defer1 :: forall a. (Unit -> l a) -> l a
68+
69+
class Lazy2 l where
70+
defer2 :: forall a b. (Unit -> l a b) -> l a b
71+
72+
73+
### Values
74+
75+
fix :: forall l a. (Lazy l) => (l -> l) -> l
76+
77+
fix1 :: forall l a. (Lazy1 l) => (l a -> l a) -> l a
78+
79+
fix2 :: forall l a b. (Lazy2 l) => (l a b -> l a b) -> l a b
6880

6981

7082
## Module Control.Monad

src/Control/Lazy.purs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
module Control.Lazy where
22

3-
class Lazy a where
4-
defer :: (Unit -> a) -> a
3+
class Lazy l where
4+
defer :: (Unit -> l) -> l
55

6-
class Lazy1 a where
7-
defer1 :: forall b. (Unit -> a b) -> a b
6+
class Lazy1 l where
7+
defer1 :: forall a. (Unit -> l a) -> l a
8+
9+
class Lazy2 l where
10+
defer2 :: forall a b. (Unit -> l a b) -> l a b
11+
12+
fix :: forall l a. (Lazy l) => (l -> l) -> l
13+
fix f = defer (\_ -> f (fix f))
14+
15+
fix1 :: forall l a. (Lazy1 l) => (l a -> l a) -> l a
16+
fix1 f = defer1 (\_ -> f (fix1 f))
17+
18+
fix2 :: forall l a b. (Lazy2 l) => (l a b -> l a b) -> l a b
19+
fix2 f = defer2 (\_ -> f (fix2 f))

0 commit comments

Comments
 (0)