gtk2hs / gtk2hs

GUI library for Haskell based on GTK+
GNU General Public License v3.0
182 stars 83 forks source link

Pango functions are not pure #150

Open tomjaguarpaw opened 8 years ago

tomjaguarpaw commented 8 years ago
Prelude> import Graphics.Rendering.Pango
Prelude Graphics.Rendering.Pango> f
Normal
Prelude Graphics.Rendering.Pango> fontDescriptionSetStyle f StyleItalic
Prelude Graphics.Rendering.Pango> f
Italic

This is astonishing. Has no one noticed this before?

bergey commented 8 years ago

That seems evident from the name & type: FontDescription -> FontStyle -> IO (). A FontDescription is a ForeignPtr, and the function certainly isn't returning a new FontDescription.

What behavior would you expect instead?

tomjaguarpaw commented 8 years ago

I would expect reading a FontDescription to require IO if its value can change!

bergey commented 8 years ago

Fair enough. The Show instances use unsafePerformIO. It's hacky, and there's certainly no corresponding Read instance.