
27 Jan
2004
27 Jan
'04
1:15 p.m.
On Tue, 27 Jan 2004, Jim Lewis wrote:
I'm new to Haskell and can't find an example to solve a trivial problem.
I have code like this: findBlank :: [] -> Int findBlank str = findIndex (==' ') str
But interpreter complains elsewhere of mismatch of Int with Maybe Int. I want to handle the maybe only here and nowhere else. (snip)
This may somehow help, findBlank' :: [Char] -> Int findBlank' str = fromJust (findIndex (==' ') str) findBlank'' :: [Char] -> Int findBlank'' str = let Just index = findIndex (==' ') str in index findBlank''' :: [Char] -> Int findBlank''' str = maybe (error "Pigs flew") id (findIndex (==' ') str) You may have to import Maybe to get some of those to work. Matthew Walton's comments also look good. -- Mark