[Haskell-cafe] Java or C to Haskell

Ketil Malde ketil+haskell at ii.uib.no
Wed Sep 20 05:17:10 EDT 2006


Carajillu <crespi.albert at gmail.com> writes:

> compare function just compares the two lists and return true if they are
> equal, or false if they are not.

> find_match "4*h&a" "4*5&a" 'h' ----> returns '5' (5 matches with the h)
> find_match "4*n&s" "4dhnn" "k" ----> returns ''  (no match at all - lists
> are different anyway)

Must they be equal the whole way, or just up to the occurrence of the
searched-for character?

  find_match (x:xs) (y:ys) c | x==c = Just y 
                             | x/=y = Nothing
                             | True = find_match xs ys c
  find_match [] [] _ = Nothing

Or, to check the whole list:

  find_match (x:xs) (y:ys) c | x==c && xs == ys = Just y 
                             | x/=y = Nothing
                             | True = find_match xs ys c
  find_match [] [] _ = Nothing

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants



More information about the Haskell-Cafe mailing list