returnIO is used in OOHaskell to return the object as a record of methods. But even on use of return instead of returnIO there is no difference in the output or object behaviour. The OOHaskell code is:
{-# LANGUAGE EmptyDataDecls, DeriveDataTypeable, TemplateHaskell #-}
{-# OPTIONS_GHC -fcontext-stack=100 #-}
module Rectangle where
import OOHaskell
$(label "getLength")
$(label "getWidth")
$(label "incr")
$(label "lengthenBy")
$(label "setLength")
$(label "setWidth")
$(label "show'")
rectangle length width self
= do
lengthRef <- newIORef length :: IO (IORef Int)
widthRef <- newIORef width :: IO (IORef Int)
return $
getLength .=. readIORef lengthRef
.*. getWidth .=. readIORef widthRef
.*. setLength .=. writeIORef lengthRef
.*. setWidth .=. writeIORef widthRef
.*. lengthenBy .=. (\dl ->
do
length <- self # getLength
(self # setLength) (length + dl))
.*. incr .=. (self # lengthenBy) (1)
.*. show' .=. printLn ("Length : "<< self # getLength<<" Width : "<< self # getWidth)
.*. emptyRecord
Can anyone please explain why is this happening? What makes the object behave in same way in both cases?
returnIO is return, but specialised to IO types.
That is:
return :: Monad m => a -> m a
returnIO :: a -> IO a
See lines 75-76 of OOHaskell.hs:
returnIO :: a -> IO a
returnIO = return
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With