Skip to content

Commit ec96e77

Browse files
committed
Merge pull request #23 from puffnfresh/bug/inconsistent-instances
Fix typo in ListT Apply
2 parents b365c87 + 6d6202b commit ec96e77

File tree

2 files changed

+103
-3
lines changed

2 files changed

+103
-3
lines changed

docs/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ data ListT f a
99
```
1010

1111

12+
#### `ZipListT`
13+
14+
``` purescript
15+
newtype ZipListT f a
16+
```
17+
18+
1219
#### `nil`
1320

1421
``` purescript
@@ -205,27 +212,55 @@ zipWith :: forall f a b c. (Monad f) => (a -> b -> c) -> ListT f a -> ListT f b
205212
```
206213

207214

215+
#### `zipList`
216+
217+
``` purescript
218+
zipList :: forall f a. ListT f a -> ZipListT f a
219+
```
220+
221+
208222
#### `semigroupListT`
209223

210224
``` purescript
211225
instance semigroupListT :: (Applicative f) => Semigroup (ListT f a)
212226
```
213227

214228

229+
#### `semigroupZipListT`
230+
231+
``` purescript
232+
instance semigroupZipListT :: (Applicative f) => Semigroup (ZipListT f a)
233+
```
234+
235+
215236
#### `monoidListT`
216237

217238
``` purescript
218239
instance monoidListT :: (Applicative f) => Monoid (ListT f a)
219240
```
220241

221242

243+
#### `monoidZipListT`
244+
245+
``` purescript
246+
instance monoidZipListT :: (Applicative f) => Monoid (ZipListT f a)
247+
```
248+
249+
222250
#### `functorListT`
223251

224252
``` purescript
225253
instance functorListT :: (Functor f) => Functor (ListT f)
226254
```
227255

228256

257+
#### `functorZipListT`
258+
259+
``` purescript
260+
instance functorZipListT :: (Functor f) => Functor (ZipListT f)
261+
```
262+
263+
229264
#### `unfoldableListT`
230265

231266
``` purescript
@@ -240,13 +275,27 @@ instance applyListT :: (Monad f) => Apply (ListT f)
240275
```
241276

242277

278+
#### `applyZipListT`
279+
280+
``` purescript
281+
instance applyZipListT :: (Monad f) => Apply (ZipListT f)
282+
```
283+
284+
243285
#### `applicativeListT`
244286

245287
``` purescript
246288
instance applicativeListT :: (Monad f) => Applicative (ListT f)
247289
```
248290

249291

292+
#### `applicativeZipListT`
293+
294+
``` purescript
295+
instance applicativeZipListT :: (Monad f) => Applicative (ZipListT f)
296+
```
297+
298+
250299
#### `bindListT`
251300

252301
``` purescript
@@ -275,20 +324,41 @@ instance altListT :: (Applicative f) => Alt (ListT f)
275324
```
276325

277326

327+
#### `altZipListT`
328+
329+
``` purescript
330+
instance altZipListT :: (Applicative f) => Alt (ZipListT f)
331+
```
332+
333+
278334
#### `plusListT`
279335

280336
``` purescript
281337
instance plusListT :: (Monad f) => Plus (ListT f)
282338
```
283339

284340

341+
#### `plusZipListT`
342+
343+
``` purescript
344+
instance plusZipListT :: (Monad f) => Plus (ZipListT f)
345+
```
346+
347+
285348
#### `alternativeListT`
286349

287350
``` purescript
288351
instance alternativeListT :: (Monad f) => Alternative (ListT f)
289352
```
290353

291354

355+
#### `alternativeZipListT`
356+
357+
``` purescript
358+
instance alternativeZipListT :: (Monad f) => Alternative (ZipListT f)
359+
```
360+
361+
292362
#### `monadPlusListT`
293363

294364
``` purescript

src/Control/Monad/ListT.purs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Control.Monad.ListT
22
( ListT()
3+
, ZipListT()
34
, catMaybes
45
, cons'
56
, drop
@@ -28,6 +29,7 @@ module Control.Monad.ListT
2829
, wrapLazy
2930
, zipWith
3031
, zipWith'
32+
, zipList
3133
) where
3234

3335
import Data.Lazy
@@ -45,7 +47,9 @@ module Control.Monad.ListT
4547
import Control.Monad.Trans
4648

4749
data ListT f a = ListT (f (Step a (ListT f a)))
48-
50+
51+
newtype ZipListT f a = ZipListT (ListT f a)
52+
4953
data Step a s =
5054
Yield a (Lazy s) |
5155
Skip (Lazy s) |
@@ -195,33 +199,51 @@ module Control.Monad.ListT
195199
zipWith f = zipWith' g where
196200
g a b = pure $ f a b
197201

202+
zipList :: forall f a. ListT f a -> ZipListT f a
203+
zipList = ZipListT
204+
198205
instance semigroupListT :: (Applicative f) => Semigroup (ListT f a) where
199206
(<>) = concat
200207

208+
instance semigroupZipListT :: (Applicative f) => Semigroup (ZipListT f a) where
209+
(<>) (ZipListT a) (ZipListT b) = ZipListT $ a <> b
210+
201211
instance monoidListT :: (Applicative f) => Monoid (ListT f a) where
202212
mempty = nil
203213

214+
instance monoidZipListT :: (Applicative f) => Monoid (ZipListT f a) where
215+
mempty = ZipListT mempty
216+
204217
instance functorListT :: (Functor f) => Functor (ListT f) where
205218
(<$>) f = stepMap g where
206219
g (Yield a s) = Yield (f a) ((<$>) f <$> s)
207220
g (Skip s) = Skip ((<$>) f <$> s)
208221
g Done = Done
209222

223+
instance functorZipListT :: (Functor f) => Functor (ZipListT f) where
224+
(<$>) f (ZipListT a) = ZipListT $ f <$> a
225+
210226
instance unfoldableListT :: (Monad f) => Unfoldable (ListT f) where
211227
-- unfoldr :: forall a b. (b -> Maybe (Tuple a b)) -> b -> ListT f a
212228
unfoldr f b = go (f b)
213229
where go Nothing = nil
214230
go (Just (Tuple a b)) = cons' (pure a) (defer \_ -> (go (f b)))
215231

216-
instance applyListT :: (Monad f) => Apply (ListT f) where
232+
instance applyListT :: (Monad f) => Apply (ListT f) where
217233
(<*>) f x = do
218234
f' <- f
219235
x' <- x
220-
return (f x)
236+
return (f' x')
237+
238+
instance applyZipListT :: (Monad f) => Apply (ZipListT f) where
239+
(<*>) (ZipListT a) (ZipListT b) = ZipListT $ zipWith g a b where g f x = f x
221240

222241
instance applicativeListT :: (Monad f) => Applicative (ListT f) where
223242
pure = singleton
224243

244+
instance applicativeZipListT :: (Monad f) => Applicative (ZipListT f) where
245+
pure = ZipListT <<< pure
246+
225247
instance bindListT :: (Monad f) => Bind (ListT f) where
226248
(>>=) fa f = stepMap g fa where
227249
g (Yield a s) = Skip (h <$> s) where h s = f a `concat` (s >>= f) -- FIXME compiler bug with overlapping instances?
@@ -236,9 +258,17 @@ module Control.Monad.ListT
236258
instance altListT :: (Applicative f) => Alt (ListT f) where
237259
(<|>) = concat
238260

261+
instance altZipListT :: (Applicative f) => Alt (ZipListT f) where
262+
(<|>) (ZipListT a) (ZipListT b) = ZipListT $ a <|> b
263+
239264
instance plusListT :: (Monad f) => Plus (ListT f) where
240265
empty = nil
241266

267+
instance plusZipListT :: (Monad f) => Plus (ZipListT f) where
268+
empty = ZipListT empty
269+
242270
instance alternativeListT :: (Monad f) => Alternative (ListT f)
243271

272+
instance alternativeZipListT :: (Monad f) => Alternative (ZipListT f)
273+
244274
instance monadPlusListT :: (Monad f) => MonadPlus (ListT f)

0 commit comments

Comments
 (0)