[Haskell-cafe] testing for same characters in lists of strings

Justin Bailey jgbailey at gmail.com
Tue Apr 8 14:17:00 EDT 2008

On Tue, Apr 8, 2008 at 10:24 AM, Jackm139 <jackmarathon at gmail.com> wrote:
>  import List
>  same :: [[Char]] -> [[Char]] -> Bool
>  same [xs] [ys] = map (normalize) [[xs]] == map (normalize) [[ys]]
>  normalize :: [String] -> [String]
>  normalize [xs] = [(sort (nub xs))]

Your pattern binding [xs] and [ys] says to only match when the list
contains one element. Otherwise, you get a pattern-matching failure at
run-time. Use "normalize xs" to match a list of strings, and "same xs
ys" to match lists of lists. xs and ys will have different types with
those patterns, but you'll get it.


More information about the Haskell-Cafe mailing list