When I was reading the documentations of SDL
in haskell, I found that some functions inevitably modifies its input. For example, blitSurface
has destination surface as input, but it is updated within the function. Now, generalizing the problem, if I have a function f :: a -> IO a
, does it break composition if I modify a
inside the function? What about f :: IO a -> IO a
? What about a -> IO ()
? And what about IO a -> IO ()
?
Considering the case that blitSurface
is actually a foreign function, and making a new surface every frame doesn't sound very efficient, these functions are hard to avoid. Will such functions cause problems in a larger scale? For example, using fModifySurface :: Surface -> IO ()
which does destructive update as an example:
main = do
w <- ... -- The window surface
-- Do something here
s <- someFuncGetSurface -- We get a surface here
fModifySurface s -- Destructively update s
blitSurface ...... -- Ignore the actual API, but destructively updates w
Are there any unexpected semantics in the code above? If so, what is the best way to make use of foreign functions that changes the input?