Skip to content

Commit 9256f60

Browse files
committed
change trampoline to use Data.Lazy, which did not exist at the time this code was written
1 parent dbd3406 commit 9256f60

File tree

3 files changed

+10
-31
lines changed

3 files changed

+10
-31
lines changed

MODULE.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,7 @@
143143

144144
### Types
145145

146-
newtype Delay a where
147-
Delay :: Unit -> a -> Delay a
148-
149-
type Trampoline a = Free Delay a
150-
151-
152-
### Type Class Instances
153-
154-
instance delayApplicative :: Applicative Delay
155-
156-
instance delayApply :: Apply Delay
157-
158-
instance delayFunctor :: Functor Delay
146+
type Trampoline a = Free Lazy a
159147

160148

161149
### Values

bower.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
"dist"
1313
],
1414
"dependencies": {
15-
"purescript-control": "0.2.1",
16-
"purescript-either": "0.1.3",
15+
"purescript-control": "*",
16+
"purescript-either": "*",
1717
"purescript-exists": "*",
18-
"purescript-transformers": "0.2.0"
18+
"purescript-transformers": "*",
19+
"purescript-lazy": "*"
1920
}
2021
}

src/Control/Monad/Trampoline.purs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
module Control.Monad.Trampoline where
22

33
import Control.Monad.Free
4+
import Data.Lazy
45

5-
newtype Delay a = Delay (Unit -> a)
6-
7-
instance delayFunctor :: Functor Delay where
8-
(<$>) f (Delay g) = Delay (const (f (g unit)))
9-
10-
instance delayApply :: Apply Delay where
11-
(<*>) (Delay f) (Delay a) = Delay (\_ -> (f unit) (a unit))
12-
13-
instance delayApplicative :: Applicative Delay where
14-
pure a = Delay (const a)
15-
16-
type Trampoline a = Free Delay a
6+
type Trampoline a = Free Lazy a
177

188
done :: forall a. a -> Trampoline a
199
done = Pure
2010

2111
suspend :: forall a. Trampoline a -> Trampoline a
22-
suspend a = Free (Delay (const a))
12+
suspend a = Free (defer (const a))
2313

2414
delay :: forall a. (Unit -> a) -> Trampoline a
25-
delay a = Free (done <$> Delay a)
15+
delay a = Free (done <$> defer a)
2616

2717
runTrampoline :: forall a. Trampoline a -> a
28-
runTrampoline = go (\(Delay f) -> f unit)
18+
runTrampoline = go force

0 commit comments

Comments
 (0)