[Haskell-cafe] cant get trivial c2hs to work

Anatoly Yakovenko aeyakovenko at gmail.com
Sat Sep 30 13:30:25 EDT 2006

I am trying to figure out how to use c2hs, so I wrote a wrapper for
asin from math.h:
$ cat ASin.chs
module MySin (mysin)

import C2HS

#include "math.h"

asin::Double -> Double
asin xx =
   {#call fun asin#} xx

and this is my main:
$ cat Main.hs
module Main where

import ASin

main = do
   putStrLn $ show $ asin 0.5

`c2hs ASin.chs` generates this:

$ cat ASin.hs
-- GENERATED by C->Haskell Compiler, version 0.14.5 Travelling
Lightly, 12 Dec 2005 (Haskell)
-- Edit the ORIGNAL .chs file instead!

{-# LINE 1 "ASin.chs" #-}module MySin (mysin)

import C2HS

asin::Double -> Double
asin xx =
   asin xx

foreign import ccall safe "ASin.h asin"
  asin :: (CDouble -> CDouble)

but, when i try to build the wone thing, i get an error that i dont understand:

$ ghc -v --make -fffi Main.hs
Glasgow Haskell Compiler, Version 6.4.2, for Haskell 98, compiled by
GHC version 6.4.2
Using package config file: /usr/lib/ghc-6.4.2/package.conf
Hsc static flags: -static
*** Chasing dependencies:
Chasing modules from: Main.hs
*** Deleting temp files

ASin.chs:2:0: parse error on input `import'

So, what am i missing?

More information about the Haskell-Cafe mailing list