
On Sun, 2007-02-04 at 19:54 +0530, Martin DeMello wrote:
I have a Data.Map.Map String -> (Layout, [String]) as follows:
type Anagrams = [String] type Cell = (Layout, Anagrams) type WordMap = Map.Map String Cell
exists str wmap = let a = Map.lookup (sort str) wmap in case a of Nothing -> False Just x -> case (find (== str) (snd x)) of Nothing -> False _ -> True
the existence test looks ugly - any more compact way to write it?
Using the Maybe Monad is one solution i think (as in: i _think_ this should work): findIt str wmap = do a <- Map.lookup (sort str) wmap return $ find (== str) (snd a) exists str wmap = case findIt str wmap of Nothing -> False Just _ -> True The Maybe monad is very nice for abstracting away all those case-expressions.