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
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to