@@ -2,18 +2,17 @@ module Example.List where
2
2
3
3
import Prelude
4
4
import Data.Array as A
5
- import Data.List.Lazy as L
6
5
import Control.Monad.Eff (Eff )
7
6
import Control.Monad.Eff.Class (liftEff )
8
7
import Control.Monad.Eff.Console (CONSOLE , log )
9
- import Control.Monad.List.Trans (ListT , runListT )
8
+ import Control.Monad.List.Trans (ListT , runListTRec , iterate , takeWhile )
10
9
import Control.MonadZero (guard )
11
10
12
11
-- based on http://hackage.haskell.org/package/list-transformer
13
12
logList :: forall eff .
14
13
ListT (Eff (console :: CONSOLE | eff )) String
15
14
-> Eff (console :: CONSOLE | eff ) Unit
16
- logList l = runListT do
15
+ logList l = runListTRec do
17
16
liftEff $ log " logging listT"
18
17
str <- l
19
18
liftEff $ log str
@@ -24,8 +23,8 @@ sumSqrs :: forall eff.
24
23
-> ListT (Eff (console :: CONSOLE | eff )) Unit
25
24
sumSqrs n = do
26
25
let
27
- nats = L . iterate (add one) zero -- lazy infinite list
28
- squares = L .toUnfoldable <<< L . takeWhile (_ <= n) $ map (\x -> x * x) nats
26
+ nats = iterate (add one) zero
27
+ squares = takeWhile (_ <= n) $ map (\x -> x * x) nats
29
28
x <- squares
30
29
y <- squares
31
30
liftEff $ log (" <" <> show x <> " ," <> show y <> " >" )
@@ -35,4 +34,4 @@ sumSqrs n = do
35
34
main :: forall eff . Eff (console :: CONSOLE | eff ) Unit
36
35
main = do
37
36
logList $ A .toUnfoldable [" one" , " two" , " three" ]
38
- runListT $ sumSqrs 10
37
+ runListTRec $ sumSqrs 10
0 commit comments