id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,difficulty,testcase,blockedby,blocking,related
3008,Strange behavior when using newtyped version of IO monad in FFI import declarations,waern,igloo,"Take a look at these two modules:

A.hs:

{{{
module A (GL) where

import Control.Monad
import Control.Monad.Trans

newtype GL a = GL (IO a) deriving (Functor, Monad, MonadIO)
}}}

B.hs:

{{{
module B where

import A

foreign import CALLCONV unsafe ""glFlush"" flush :: GL ()
}}}

Now, compile them with optimizations:

{{{
[david@alonzo temp]$ $HOME/ghc-6.10.1/bin/ghc A.hs B.hs -XGeneralizedNewtypeDeriving -XForeignFunctionInterface -DCALLCONV=ccall -XCPP -O
compilation IS NOT required
compilation IS NOT required
A.o:(.text+0x8e): undefined reference to `mtlzm1zi1zi0zi2_ControlziMonadziTrans_ZCDMonadIO_con_info'
A.o:(.text+0x237): undefined reference to `__stginit_mtlzm1zi1zi0zi2_ControlziMonadziTrans_'
B.o:(.text+0x1e): undefined reference to `glFlush'
/home/david/ghc-6.10.1//lib/ghc-6.10.1/libHSrts.a(Main.o): In function `real_main':
Main.c:(.text+0x12): undefined reference to `__stginit_ZCMain'
Main.c:(.text+0x26): undefined reference to `ZCMain_main_closure'
collect2: ld returnerade avslutningsstatus 1
}}}

It's OK - we pass the typechecking phase.

Now, see what happens when we compile without `-O`:

{{{
[david@alonzo temp]$ rm -f *.hi *.o
[david@alonzo temp]$ $HOME/ghc-6.10.1/bin/ghc A.hs B.hs -XGeneralizedNewtypeDeriving -XForeignFunctionInterface -DCALLCONV=ccall -XCPP

B.hs:5:0:
    Unacceptable result type in foreign declaration: GL ()
    When checking declaration:
        foreign import ccall unsafe ""static  &glFlush"" flush :: GL ()
}}}

Putting everything into one single module makes the type error go away completely (that is, also when compiling without `-O`).

Something strange must be going on.",bug,closed,normal,7.4.1,Compiler (FFI),6.10.1,fixed,FFI,david.waern@…,Linux,x86_64 (amd64),None/Unknown,Unknown,,,,
