[Haskell-beginners] Re: [Haskell-cafe] Defining a containing function on polymorphic list

Thomas Davie tom.davie at gmail.com
Mon Dec 22 09:31:35 EST 2008


On 22 Dec 2008, at 15:18, Andrew Wagner wrote:

> Yes, of course, sorry for the typo.
>
> On Mon, Dec 22, 2008 at 9:17 AM, Denis Bueno <dbueno at gmail.com> wrote:
> 2008/12/22 Andrew Wagner <wagner.andrew at gmail.com>:
> > The problem here is even slightly deeper than you might realize. For
> > example, what if you have a list of functions. How do you compare  
> two
> > functions to each other to see if they're equal? There is no good  
> way really
> > to do it! So, not only is == not completely polymorphic, but it  
> CAN'T be.
> >
> > There is a nice solution for this, however, and it's very simple:
> >
> > contain :: Eq a -> [a] -> Bool
>
> Please note that the syntax here should be:
>
>    contain :: Eq a => a -> [a] -> Bool
>
>                              Denis

Of note, unless this is an exercise, such a function already exists --  
it's called elem.

How do you find such a function?  You search on haskell.org/hoogle.

http://haskell.org/hoogle/?hoogle=Eq+a+%3D%3E+a+-%3E+%5Ba%5D+-%3E+Bool

Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20081222/ad44253f/attachment.htm


More information about the Beginners mailing list