
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? Michael

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 8/28/10 20:43 , michael rice wrote:
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-----

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

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 8/28/10 22:15 , michael rice wrote:
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>
Huh. I understood it to be defined in the Prelude, but didn't check. Looks like it's now in Control.Monad.Instances (a relatively new module). Confusing.... - -- 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/ iEYEARECAAYFAkx5yW0ACgkQIn7hlCsL25VpMACeJR2GVmy1XvOMLtze7s0z3jaZ t5sAnirMJhfh4ZYdMzJBdPbdUs8s166L =OXTs -----END PGP SIGNATURE-----

Thanks, Brandon.
Michael
--- On Sat, 8/28/10, Brandon S Allbery KF8NH
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>
Huh. I understood it to be defined in the Prelude, but didn't check. Looks like it's now in Control.Monad.Instances (a relatively new module). Confusing.... - -- 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/ iEYEARECAAYFAkx5yW0ACgkQIn7hlCsL25VpMACeJR2GVmy1XvOMLtze7s0z3jaZ t5sAnirMJhfh4ZYdMzJBdPbdUs8s166L =OXTs -----END PGP SIGNATURE-----

On 29 August 2010 02:06, Brandon S Allbery KF8NH
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 8/28/10 20:43 , michael rice wrote:
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.
One might also say its a historical accident that Either isn't an instance of Bifunctor - "Equal rights for Lefts!", but that's another story...

On 29 August 2010 16:51, Stephen Tetley
One might also say its a historical accident that Either isn't an instance of Bifunctor - "Equal rights for Lefts!", but that's another story...
One might also say that that's because there is no BiFunctor in the report, standard library, etc. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Looks like the fmap definition for the Either functor matches what's given in Learn You A Haskell ...
instance Functor (Either a) where
fmap f (Right x) = Right (f x)
fmap f (Left x) = Left x
but Hoogle couldn't find Control.Monad.Instances
How else can I look at the code?
Michael
[michael@localhost ~]$ ghci
GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :m + Control.Monad.Instances
Prelude Control.Monad.Instances> :m + Data.Either
Prelude Control.Monad.Instances Data.Either> let l = Left 5
Prelude Control.Monad.Instances Data.Either> fmap (*2) l
Left 5
Prelude Control.Monad.Instances Data.Either> let r = Right "five"
Prelude Control.Monad.Instances Data.Either> fmap length r
Right 4
--- 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

On 30 August 2010 14:25, michael rice
Looks like the fmap definition for the Either functor matches what's given in Learn You A Haskell ...
instance Functor (Either a) where fmap f (Right x) = Right (f x) fmap f (Left x) = Left x
but Hoogle couldn't find Control.Monad.Instances
How else can I look at the code?
http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Control-M... -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Hi Ivan,
I already looked there and didn't find anything, but went back and noticed the "Source Code" at the top right of the page and found it there. Why are there two source codes, the one at the top and the ones down the right margin (all the same from what I can tell).
Michael
--- On Mon, 8/30/10, Ivan Lazar Miljenovic
Looks like the fmap definition for the Either functor matches what's given in Learn You A Haskell ...
instance Functor (Either a) where fmap f (Right x) = Right (f x) fmap f (Left x) = Left x
but Hoogle couldn't find Control.Monad.Instances
How else can I look at the code?
http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Control-M... -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

On 30 August 2010 14:50, michael rice
Hi Ivan,
I already looked there and didn't find anything, but went back and noticed the "Source Code" at the top right of the page and found it there. Why are there two source codes, the one at the top and the ones down the right margin (all the same from what I can tell).
The ones on the side are direct links to the sources for a particular function/value/etc.; the top one just links to the file. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com
participants (4)
-
Brandon S Allbery KF8NH
-
Ivan Lazar Miljenovic
-
michael rice
-
Stephen Tetley