Skip to content

Commit dde33a8

Browse files
committed
code cleanup and get exporting working
1 parent 4ac918e commit dde33a8

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
### Types
66

7-
data ListT f a
7+
data ListT f a where
8+
ListT :: f (Step a (ListT f a)) -> ListT f a
9+
10+
data Step a s where
11+
Yield :: a -> Lazy s -> Step a s
12+
Skip :: Lazy s -> Step a s
13+
Done :: Step a s
814

915

1016
### Type Class Instances
@@ -70,6 +76,10 @@
7076

7177
wrapLazy :: forall f a. (Monad f) => Lazy (ListT f a) -> ListT f a
7278

79+
zipWith :: forall f a b c. (Monad f) => (a -> b -> c) -> ListT f a -> ListT f b -> ListT f c
80+
81+
zipWith' :: forall f a b c. (Monad f) => (a -> b -> f c) -> ListT f a -> ListT f b -> ListT f c
82+
7383

7484
## Module Data.List
7585

src/Control/Monad/ListT.purs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Control.Monad.ListT
2-
( ListT()
2+
( ListT(..) -- FIXME: compiler bug: error in exports (wrong kind) unless constructor is exported
3+
, Step(..) -- FIXME: have to export this for the preceding export
34
, nil
45
, cons'
56
, prepend'
@@ -64,8 +65,8 @@ module Control.Monad.ListT
6465

6566
concat :: forall f a. (Applicative f) => ListT f a -> ListT f a -> ListT f a
6667
concat x y = stepMap f x where
67-
f (Yield a s) = Yield a (g <$> s) where g s = s <> y
68-
f (Skip s) = Skip (g <$> s) where g s = s <> y
68+
f (Yield a s) = Yield a (flip (<>) y <$> s)
69+
f (Skip s) = Skip (flip (<>) y <$> s)
6970
f Done = Skip (defer $ const y)
7071

7172
instance semigroupListT :: (Applicative f) => Semigroup (ListT f a) where
@@ -88,7 +89,7 @@ module Control.Monad.ListT
8889

8990
instance bindListT :: (Monad f) => Bind (ListT f) where
9091
(>>=) fa f = stepMap g fa where
91-
g (Yield a s) = Skip (h <$> s) where h s = f a `concat` (s >>= f) -- why overlapping instances?
92+
g (Yield a s) = Skip (h <$> s) where h s = f a `concat` (s >>= f) -- FIXME compiler bug with overlapping instances?
9293
g (Skip s) = Skip (h <$> s) where h s = s >>= f
9394
g Done = Done
9495

@@ -124,7 +125,7 @@ module Control.Monad.ListT
124125

125126
takeWhile :: forall f a. (Applicative f) => (a -> Boolean) -> ListT f a -> ListT f a
126127
takeWhile f = stepMap g where
127-
-- type inferencer bug with if/then/else !!!!!
128+
-- FIXME: type inferencer bug with if/then/else
128129
g (Yield a s) = ifThenElse (f a) (Yield a (takeWhile f <$> s)) Done where ifThenElse p a b = if p then a else b
129130
g (Skip s) = Skip $ takeWhile f <$> s
130131
g Done = Done

0 commit comments

Comments
 (0)