<div dir="ltr"><div>Hi,</div><div><br></div><div>I can't get the FFI to work as advertised - any ideas?</div><div><br></div><div>Thanks,</div><div><br></div><div>Nawal.</div><div><br></div><div><br></div><div>Tutorial from here:</div><div><a href="http://book.realworldhaskell.org/read/interfacing-with-c-the-ffi.html" target="_blank">http://book.realworldhaskell.<wbr>org/read/interfacing-with-c-<wbr>the-ffi.html</a><br></div><div><br></div><div>$ cat fore.hs </div><div>{-# LANGUAGE ForeignFunctionInterface #-}</div><div><br></div><div>import Prelude</div><div><br></div><div>import Foreign</div><div>import Foreign.C.Types</div><div><br></div><div>foreign import ccall "math.h sin"</div><div>     c_sin :: CDouble -> CDouble</div><div><br></div><div>fastsin :: Double -> Double</div><div>fastsin x = realToFrac (c_sin (realToFrac x))</div><div><br></div><div><br></div><div>main = print (fastsin 0.5)</div><div><br></div><div>$ jhc -phaskell2010 fore.hs -o bin/fore</div><div>jhc -phaskell2010 fore.hs -o bin/fore</div><div>jhc 0.8.2 (mydniquipepo-32)</div><div>Finding Dependencies...</div><div>Using Ho Cache: '/home/nawal/.jhc/cache'</div><div>Main                    [fore.hs]</div><div>Typechecking...</div><div>[1 of 1] Main             (......................jhc: user error (</div><div>What:    failure</div><div>Why:     context reduction, no instance for: Jhc.Class.Real.Fractional Jhc.Type.C.CDouble</div><div>Where:   on line 12 in fore.hs</div><div>in the explicitly typed Main.fastsin Main.1_x</div><div>  = Jhc.Num.realToFrac (Main.c_sin (Jhc.Num.realToFrac Main.1_x))               {- on line 12 -}</div><div>Compilation of module: Main)</div><div><br></div><div><br></div><div><br></div></div>