haddock, instances and defining modules

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Thu Oct 18 11:10:22 CEST 2012


On 18 October 2012 19:52, Daniel Gorín <dgorin at dc.uba.ar> wrote:
> Hi
>
> The haddock page for Data.Either lists an instance Functor (Either a). However, this instance doesn't get in scope when importing Data.Either. E.g., the following program fails to compile:
>
>> import Data.Either
>>
>> main = print $ fmap not $ Right "hello"

Are you sure of this code?

$ghci
GHCi, version 7.4.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> fmap not $ Right "hello"

<interactive>:2:18:
    Couldn't match expected type `Bool' with actual type `[Char]'
    In the first argument of `Right', namely `"hello"'
    In the second argument of `($)', namely `Right "hello"'
    In the expression: fmap not $ Right "hello"


>
> AFAIK, one needs to import Control.Monad.Instances instead to get such an instance; but there is nothing in the haddock page of Data.Either that suggests it. This can be quite frustrating for beginners!

I just started up ghci without importing anything (except the Prelude)
and didn't have a problem; this is GHC 7.4.2.

>
> It would be good if the docs could be improved here, but I'm not sure what to suggest (maybe haddock should be generating something else in these cases?)… Any thoughts?
>
> Thanks,
> Daniel
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries



-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com



More information about the Libraries mailing list