Thomas Hoefer writes:
> Hi
>
> I try to use C-Pointers in Haskell by invoking GreenCard 2.0.
>
> The C-Function I want to use is declared like this:
>
> > %fun listTo :: Int -> [Int] within the Haskell-source and
> > int *listTo( int i ) within the C-source
>
> Now, what GreenCard 2.0 makes out of that is the following:
>
> > listTo :: Int -> [Int]
> > listTo arg1 =
> > unsafePerformIO(
> > _casm_ ``do {int arg1;;
> > arg1 = %0;
> > do {res1 = listTo(arg1);;} while(0);} while(0);'' arg1
> > (unmarshall_listLenTypeVar "Int" res1 res2) >>= \ gc_res1 ->
> > (return (gc_res1)))
>
> So far, so good. But now GHC 3.01 complains that:
>
> > GHC-C-gc.hs:41: Value not in scope: `unmarshall_listLenTypeVar_'
> >
> > GHC-C-gc.hs:41: Value not in scope: `res1'
> >
> > GHC-C-gc.hs:41: Value not in scope: `res2'
>
Hi,
looks like you've hit a Dark Corner of the Green Card
implementation. The automatic fill in of list DISes
has a couple of problems, and until these are sorted out, could
you just manually give the %call and %result lines, i.e.,
%fun listTo :: Int -> [Int]
%result (listLenInt (int {len}) (addr {ptr}))
Notice that the marshall_listLenInt and unmarshall_listLenInt
functions are not provided by StdDIS, you'll have to write them
yourself.
BTW, the new IDL compiler will solve this latter problem,
automatically generating code for marshalling and unmarshalling (IDL)
data types. (A preliminary snapshot is now available via
http://www.dcs.gla.ac.uk/fp/software/hdirect/ )
--Sigbjorn