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

Ryan Ingram ryani.spam at gmail.com
Wed Dec 24 10:07:14 EST 2008


Here's a tip: leave off the type signature, and ask ghci what it is.

$ ghci
Prelude> let contain x [] = False ; contain x (y:ys) = if x == y then
True else contain x ys
Prelude> :t contain
contain :: (Eq a) => a -> [a] -> Bool

  -- ryan

2008/12/22 Raeck Zhao <raeck at msn.com>:
> I am trying to define a containing function to see if a value is one of the
> elements within a list which is polymorphic, but failed with the following
> codes:
>> contain :: a -> [a] -> Bool
>> contain x [] = False
>> contain x (y:ys) = if x == y then True else contain x ys it seems that the
>> problem is the 'operator' == does not support a polymorphic check?
> Any way can solve the problem? or any alternative solution to achieve the
> purpose?
> Thanks!
> Raeck
>
> ________________________________
> It's the same Hotmail(R). If by "same" you mean up to 70% faster. Get your
> account now.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list