ekmett / contravariant

Haskell 98 contravariant functors
http://hackage.haskell.org/package/contravariant
Other
73 stars 24 forks source link

Make SettableStateVar instances for Decidable and Divisible visible #30

Closed rahulmutt closed 7 years ago

rahulmutt commented 7 years ago
import Data.StateVar
import Data.Functor.Contravariant
import Data.Functor.Contravariant.Divisible

-- No instance for (Decidable SettableStateVar)
ssv1 :: SettableStateVar String
ssv1 = lose (\_ -> undefined)

-- No instance for (Divisible SettableStateVar)
ssv2 :: SettableStateVar String
ssv2 = conquer

-- Typechecks without error, meaning the Contravariant instance is visible
contra :: SettableStateVar String
contra = contramap length (makeSettableStateVar undefined :: SettableStateVar Int)

Compiling the above program reveals that the Decidable and Divisible instances do not exist for SettableStateVar even though they are clearly defined in the Data.Functor.Contravariant.Divisible. The problem is the use of #if MIN_VERSION_StateVar instead of #ifdef MIN_VERSION_StateVar.

This extremely subtle bug was discovered when trying to compile contravariant with Eta and it resulted in a cpphs failure.

This PR fixes the problem.

RyanGlScott commented 7 years ago

Oops. Nice catch!