[Haskell] Using putStrLn/printf from DLL in GUI application

Sven Panne sven.panne at aedion.de
Sat Dec 2 12:08:21 EST 2006


Am Freitag, 1. Dezember 2006 21:37 schrieb Krasimir Angelov:
> [...]
> do allocConsole
>      .....
>      .....
>      putStrLn "Hello, world!"
>      .....
>      .....
>      freeConsole
> [...]

Having explicit alloc/free pairs can lead to resource leaks in the presence of 
exceptions. Simple solution: Merge both parts into a single function, using 
"bracket" or friends internally:

   withConsole $ do
      ...
      putStrLn "I'm exception safe! :-)"
      ...

Cheers,
   S.


More information about the Haskell mailing list