Possible runtime overhead of wrapping the IO monad?

John Meacham john at repetae.net
Mon Mar 27 17:51:33 EST 2006


On Mon, Mar 27, 2006 at 08:14:40PM +0100, Brian Hulley wrote:
> However I'm wondering if I can rely on all this monad stuff being optimized 
> out at compile time. A sample monad is below:
> 
>   newtype VertexM a = VertexM (IO a)
> 

in GHC you can actually guarentee there is no overhead with the newtype
deriving feature. 

>   newtype VertexM a = VertexM (IO a)
>                    deriving(Monad,Functor,MonadIO)

now it will use the exact same dictionaries as the IO monad.

the newtype deriving feature is very very useful for this sort of
thing, or when you need to make an alternate type that has almost all
the qualities of another one, you can newtype-derive all the same bits
and just provide the instance for the different one.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈


More information about the Glasgow-haskell-users mailing list