
23 Dec
2008
23 Dec
'08
10:48 p.m.
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'" ?