[Haskell-cafe] Re: Java or C to Haskell
Jón Fairbairn
jon.fairbairn at cl.cam.ac.uk
Wed Sep 20 06:20:42 EDT 2006
Carajillu <crespi.albert at gmail.com> writes:
> That works good, but I have a problem with the return type, I forgot to
> mention... can it be a [char]??
If that's what you want, how about this:
import Maybe
find_match l1 l2 c
= fmap catMaybes . sequence $ zipWith match l1 l2
where match a b
| a == c = Just (Just b)
| a == b = Just Nothing
| otherwise = Nothing
although part of the reason for writing it like that is to
make you work hard to understand it ;-) ... and it returns
Maybe [Char] since I can't bring myself to use "" to
indicate failure... but judicious use of catMaybes
. concat. maybeToList might help with that.
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-Cafe
mailing list