[C2hs] Passing extra arguments to marshalling functions
Manuel M T Chakravarty
chak at cse.unsw.edu.au
Sun Jun 3 23:40:50 EDT 2007
Björn,
> I have a function for checking return values of functions:
>
> checkResult :: String -> CInt -> IO ()
> checkResult _ 0 = return ()
> checkResult f n = fail $ f ++ " failed (" ++ show n ++ ")"
>
> Now, I want to call that on the exit value of lots of functions, like this:
>
> {#fun foo
> {}
> -> `()' `checkResult "foo"'*- #}
>
> {#fun bar
> {}
> -> `()' `checkResult "bar"'*- #}
>
> ...
>
> However, the marshallers can only be function names, not arbitrary
> expressions. Wouldn't it be a useful generalization to allow arbitrary
> expressions as marshallers? That way you could even have one-off
> marshallers as lambda expressions.
Yes I thought about having something like that. On the other hand, its
also quite easy to just follow the fun hook with a where clause that
introduces a name for the marshalling expression, but I admit that if
its just a partial application, as in your case, even a where clause is
somewhat tedious in comparison. Do you want to try adding this to c2hs?
I'd be happy to include a suitable patch.
Cheers,
Manuel
More information about the C2hs
mailing list