Gabriella439 / foldl

Composable, streaming, and efficient left folds
BSD 3-Clause "New" or "Revised" License
159 stars 51 forks source link

Documented property for prefilterM doesn't type check #187

Closed chris-martin closed 1 year ago

chris-martin commented 1 year ago

The docs for prefilterM include the following statement:

foldM (prefilterM p folder) list = foldM folder (filter p list)

On the left side, p has type a -> m Bool. On the right side, it has type a -> Bool.

The property can be made to type check, but it would no longer be correct:

foldM (prefilterM p folder) list  =  foldM folder =<< Control.Monad.filterM p list

Because then on the left side, the effects of p are interleaved throughout the folding, whereas on the right side they happen all upfront.

I am not sure what correct property could be salvaged here, other than to restrict the monadic context to Identity:

foldM (prefilterM (Identity . p) folder) list = foldM folder (filter p list)
Gabriella439 commented 1 year ago

I think it's fine to delete the property