FFI : A failing example

Francis Girard francis.girard@free.fr
Tue, 22 Oct 2002 05:41:01 +0200


I'm a beginner trying to use FFI. I copied the example given in :

The Glasgow Haskell Compiler User's Guide, Version 5.04
Chapter 8. Foreign function interface (FFI)

module Foo where

foreign export ccall foo :: Int -> IO Int

foo :: Int -> IO Int
foo n = return (length (f n))

f :: Int -> [Int]
f 0 = []
f n = n:(f (n-1))

Copied it verbatim. And simply tried to compile it using "ghc -c Foo.hs -o 
Foo.o" and always got the error :

Type signature given for an expression (at the line following the "foreign 

I then tried to import the "Foreign" and "Foreign.C" modules but it didn't 
change anything.

I am missing something and I would be VERY grateful to anyone that tells me 

Thank you

Francis Girard
Le Conquet (France)