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

Henning Thielemann schlepptop at henning-thielemann.de
Tue Dec 23 22:48:19 EST 2008


Andrew Wagner schrieb:
> 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
> contain x [] = False
> contain x (y:ys) = if x == y then True else contain x ys

Would HLint jump in here and suggest:
   contain x (y:ys) = x == y || contain x ys
 ? Or even "replace 'contain' by 'elem'" ?


More information about the Haskell-Cafe mailing list