[Haskell-cafe] On to applicative

michael rice nowgate at yahoo.com
Mon Aug 30 00:25:22 EDT 2010

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 at 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 <allbery at ece.cmu.edu> wrote:

From: Brandon S Allbery KF8NH <allbery at ece.cmu.edu>
Subject: Re: [Haskell-cafe] On to applicative
To: haskell-cafe at haskell.org
Date: Saturday, August 28, 2010, 9:06 PM

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-typeclass
> 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 at kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university      KF8NH
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

Haskell-Cafe mailing list
Haskell-Cafe at haskell.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100829/b07e4a6a/attachment.html

More information about the Haskell-Cafe mailing list