[Haskell-beginners] maybe in IO

Krzysztof Skrzętnicki gtener at gmail.com
Thu Aug 1 17:35:22 CEST 2013


Of course there is "return ()" missing.

check x assoc = case lookup x of
                    Just found -> putStrLn ("found " ++ found)
                     _ -> return ()


On Thu, Aug 1, 2013 at 5:34 PM, Krzysztof Skrzętnicki <gtener at gmail.com>wrote:

> I'd rather use pattern matching in this case:
>
> check x assoc = case lookup x of
>                     Just found -> putStrLn ("found " ++ found)
>                     _ ->
>
> Not really shorter but I think it's cleaner this way.
>
>
>
>
> On Thu, Aug 1, 2013 at 5:00 PM, vold <voldermort at hotmail.com> wrote:
>
>> I've defined a function similar to
>>
>> check x assoc = let found = lookup x assoc in
>>                     when (isJust found) $ putStrLn $ "found " ++ fromJust
>> found
>>
>> which I've used several times from within the IO monad. Is there a more
>> compact way of doing this?
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130801/b74b275a/attachment.htm>


More information about the Beginners mailing list