[Haskell-cafe] Definition of List type?
Ben Millwood
haskell at benmachine.co.uk
Fri Jul 30 16:21:15 EDT 2010
On Fri, Jul 30, 2010 at 8:54 PM, michael rice <nowgate at yahoo.com> wrote:
>
> Thanks all,
>
> Now that I have a (very) rudimentary understanding of Haskell, I figured I'd back up and have a closer (conceptual) look at type definitions to see what they have in common, and just happen to pick Maybe and List.
>
> I also noticed Maybe has a list of "Instances"
>
> Monad Maybe
> Functor Maybe
> Typeable1 Maybe
> MonadFix Maybe
> MonadPlus Maybe
> etc.
>
> while List has none, at least I don't see any in Data.List. Same reason?
>
> From "Learn You A Haskell:"
>
> "If a type is a part of a typeclass, that means it supports and implements the behavior the typeclass describes."
>
> I'm way out on a limb here, but isn't Monad a typeclass? and if, as we say above, that Maybe is an instance of Monad, wouldn't there have to be
>
> instance Monad Maybe where
> return = ... -- return for Maybe
> >>= = ... -- bind for Maybe
> etc.
>
> somewhere? Where? It's not in Data.Maybe. Is there some kind of scheme for defining this stuff, i.e., this goes here, that goes there?
>
It *is* in Data.Maybe:
http://hackage.haskell.org/packages/archive/base/4.2.0.1/doc/html/src/Data-Maybe.html
Generally speaking a type class instance should go either where the
type is defined, or where the class is defined, although there are
exceptions. In any case, if you can get the instance loaded in ghci,
you can find out where its defined:
ghci> :i Maybe
data Maybe a = Nothing | Just a -- Defined in Data.Maybe
instance (Eq a) => Eq (Maybe a) -- Defined in Data.Maybe
instance Monad Maybe -- Defined in Data.Maybe
instance Functor Maybe -- Defined in Data.Maybe
instance (Ord a) => Ord (Maybe a) -- Defined in Data.Maybe
instance (Read a) => Read (Maybe a) -- Defined in GHC.Read
instance (Show a) => Show (Maybe a) -- Defined in GHC.Show
More information about the Haskell-Cafe
mailing list