haskell / attoparsec

A fast Haskell library for parsing ByteStrings

Home Page:http://hackage.haskell.org/package/attoparsec

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strictness inconsistency

treeowl opened this issue · comments

We have

instance Monad (Parser i) where
    m >>= k = Parser $ \t !pos more lose succ ->
        let succ' t' !pos' more' a = runParser (k a) t' pos' more' lose succ
        in runParser m t pos more lose succ'

but

instance Applicative (Parser i) where
    pure v = Parser $ \t pos more _lose succ -> succ t pos more v

Thus pure x is lazy in the position but pure x >>= pure is strict in it. Is there a reason for this (admittedly mild) violation of the monad laws? If not, I would suggest

   pure v = Parser $ \t !pos more _lose succ -> succ t pos more v

It's even possible that this change will help hold GHC's hand a little better.