Possible runtime overhead of wrapping the IO monad?

Benjamin Franksen benjamin.franksen at bessy.de
Fri Mar 31 08:08:19 EST 2006


On Thursday 30 March 2006 14:13, Brian Hulley wrote:
> John Meacham wrote:
> > On Thu, Mar 30, 2006 at 03:50:06AM +0100, Brian Hulley wrote:
> >> where the intention is that the callback will take the width and
> >> height of the window and return a RenderM action, the problem is
> >> that because the FFI does not allow RenderM to appear in a foreign
> >> type.
> >
> > it should, the types in foreign declarations should "see through"
> > newtypes.
>
> Unfortunately GHC does not seem to support this:
>
>    foreign import ccall duma_clear :: Word.Word32 -> RenderM ()
>
>        Unacceptable result type in foreign declaration: RenderM ()
>        When checking declaration:
>        foreign import ccall safe "static  &duma_clear"
>             duma_clear :: GHC.Word.Word32 -> RenderM ()
>
> even though the FFI spec agrees with you (Section 3.2):
>
>      The argument types ati produced by fatype must be
>      marshallable foreign types; that is, each ati is either (1)
>      a basic foreign type or (2) a type synonym or renamed
>      datatype of a marshallable foreign type. Moreover, the
>      result type rt produced by frtype must be a
>      marshallable foreign result type; that is,
>      it is either a marshallable foreign type, ...

Note that the addendum continues 

"...that is, it is either a marshallable foreign type, the type (), or a 
type matching Prelude.IO t, where t is a marshallable foreign type or 
()."

Nowhere is it written that 'IO t' (in itself) is a marshallable type 
whenever 't' is a marshallable type.

[I am not sure what it means exactly if a type "matches" 'Prelude.IO 
t'.]

Thus, GHC does nothing wrong, according to the addendum. That doesn't 
mean allowing IO-equivalent newtypes wouldn't be a good idea. It is 
just not written in the addendum.

Ben


More information about the Glasgow-haskell-users mailing list