[More work on chapter 5 John Goerzen **20070603212918] { hunk ./en/ch05-typeclasses.xml 25 - Naive Equality naiveeq.hs + Naive Equality -- Colors (naiveeq.hs) hunk ./en/ch05-typeclasses.xml 43 - Now, let's say that you want to add + Now, let's say that you want to add an equality test for + Strings. + Since a Haskell String is a list of characters, we can + write a simple function to perform that test, as seen in . For simplicity, we + cheat a bit and use the == operator a couple + of times. hunk ./examples/ch05/naiveeq.hs 13 +{-- snippet string --} +stringEq :: [Char] -> [Char] -> Bool +-- Match if both are empty +stringEq [] [] = True +-- Evaluate when we have only one character in both +stringEq [x] [y] = x == y +-- If both start with the same char, check the rest +stringEq (x:xs) (y:ys) = + if x == y + then stringEq xs ys + else False +-- Everything else doesn't match +stringEq _ _ = False +{-- /snippet string --} }