ApplicativeDo fails to sequence actions
Consider the following,
{-# LANGUAGE ApplicativeDo #-}
module Fail where
data P a = P
instance Functor (P) where
fmap _ P = P
instance Applicative (P) where
P <*> P = P
pure _ = P
action :: P Int
action = P
works :: P (Int, Int)
works = do
a <- action
b <- action
return (a,b)
thisWorks :: P Int
thisWorks = action *> action
-- It seems like this should be equivalent to thisWorks.
shouldThisWork :: P Int
shouldThisWork = do
action
action
It seems to me that thisWorks and shouldThisWork are equivalent, yet the latter fails to typecheck. It seems that ApplicativeDo fails to catch the fact that the result of the first action is not bound and therefore can be sequenced with *>.
Edited by Ben Gamari