snoyberg / mono-traversable

Type classes for mapping, folding, and traversing monomorphic containers
155 stars 64 forks source link

Functor instance for MinLen breaks abstraction #82

Closed snoyberg closed 9 years ago

snoyberg commented 9 years ago

Simple demonstration of the problem:

import Data.MinLen

len1 :: MinLen (Succ Zero) [()]
len1 = mlcons () (toMinLenZero [])

len0 :: MinLen (Succ Zero) [()]
len0 = fmap (drop 1) len1

main :: IO ()
main = print $ Data.MinLen.head len0

Results in:

Data.MonoTraversable.headEx: empty

I see no option but to release a new major version with the Functor instance removed. Slightly tweaked: we can make the Functor instance apply only to MinLen Zero.

Pinging @gregwebs, in case you have another idea.

gregwebs commented 9 years ago

Functor instance should act on what is inside the newtype, not the newtype itself

snoyberg commented 9 years ago

If we try to implement that, we'd have to change the kind of MinLen, and most likely lose support for monomorphic containers in the process. What you're describing is handled by the MonoFunctor instance right now.

gregwebs commented 9 years ago

Ok