
So fmap is undefined for Either? Why make Either a functor and not define fmap?
Michael
Prelude> let l = Left 3
Prelude> let r = Right "foo"
Prelude> :t l
l :: Either Integer b
Prelude> :t r
r :: Either a [Char]
Prelude> fmap (*2) l
<interactive>:1:0:
No instance for (Functor (Either Integer))
arising from a use of `fmap' at <interactive>:1:0-10
Possible fix:
add an instance declaration for (Functor (Either Integer))
In the expression: fmap (* 2) l
In the definition of `it': it = fmap (* 2) l
Prelude>
--- On Sat, 8/28/10, Brandon S Allbery KF8NH
I'm looking at a discussion of Either (as functor) here:
http://learnyouahaskell.com/making-our-own-types-and-typeclasses#the-functor...
instance Functor (Either a) where fmap f (Right x) = Right (f x) fmap f (Left x) = Left x
And this line in Data.Either
Functor (Either a)
but no fmap defined here.
How come?
Historical accident, to wit: Haskell 98 minimally defined Either in the Prelude, so in practice we get the basic definitions (Either itself and its Functor and Monad instances) from the Prelude and other utility functions from Data.Either. - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx5sq4ACgkQIn7hlCsL25WA+QCeKUOuNN4kUpci9fH6BcFZ5WqG bX8AoIBImpWLoxVz7kcwVIuHycYR/v5G =EaIs -----END PGP SIGNATURE----- _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe