[Haskell-cafe] Definition of List type?

michael rice nowgate at yahoo.com
Fri Jul 30 17:27:34 EDT 2010

Hi Daniel,

OK, now I'm getting somewhere. I was looking here:


instead of in the source.

Seem to be on the right track. I'm going to do some more poking around.

Thanks a lot, guys.


--- On Fri, 7/30/10, Daniel Fischer <daniel.is.fischer at web.de> wrote:

From: Daniel Fischer <daniel.is.fischer at web.de>
Subject: Re: [Haskell-cafe] Definition of List type?
To: haskell-cafe at haskell.org
Cc: "michael rice" <nowgate at yahoo.com>
Date: Friday, July 30, 2010, 4:23 PM

On Friday 30 July 2010 21:54:20, michael rice 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?

Data.List provides only functions for working with lists, while Data.Maybe 
also contains the definition of the type.

Type class instances are documented
- at the type class
- at the data type

Since the list datatype isn't documented like the other types (probably 
because it's not defined in valid Haskell but built-in), the list instances 
appear only at the type classes (and at the Monad documentation, you find 
"Monad []" listed as the first instance.

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

Yes, there is. In GHC at least, it's defined in Data.Maybe:

instance  Monad Maybe  where
    (Just x) >>= k      = k x
    Nothing  >>= _      = Nothing

    (Just _) >>  k      = k
    Nothing  >>  _      = Nothing

    return              = Just
    fail _              = Nothing

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

Instance declarations should be in the same module where
- the class is defined, or
- the type is defined
if possible.

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

More information about the Haskell-Cafe mailing list