[Haskell-beginners] maybe in IO

Michael Orlitzky michael at orlitzky.com
Thu Aug 1 17:45:02 CEST 2013


On 08/01/2013 11:00 AM, vold 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?
> 

maybe (return ()) (putStrLn . ("found " ++)) found

is the best I could do.





More information about the Beginners mailing list