[haskell-llvm] Beginner - Anonymous Functions
Elliott Pace
etp20 at cam.ac.uk
Fri Nov 18 15:55:47 GMT 2011
On Fri, Nov 18, 2011 at 3:02 PM, Henning Thielemann <
lemming at henning-thielemann.de> wrote:
> I have still no idea, what you actually want to achieve in the end.
I'd like to have "curried" functions. To do this, I need to track
previously entered arguments to a function. The way in which I'm doing this
is that a function value (which is called using call') is a pair of
pointers, one to the code of the function and one to the linked list of
arguments.
So, a function that is "naturally" Int -> Int -> Int, would be something
like:
plus x y = x + y;
Transforms to:
plus is a pair of pointers ( pointer to f_plus, null pointer ), to call
plus with an x, we give f_plus(x, null_pointer):
f_plus(x, previous_args):
ptr = malloc(2)
ptr[0] = x
ptr[1] = previous_args
res = malloc(2)
res[0] = f_plus'
res[1] = ptr
return res
f_plus' will then walk the linked list to get x, and sum it with the passed
in y.
Have I made sense with that?
What problems does it cause?
>
Trying:
call' :: Value (FunctionValue (LLNodePtr a -> b -> IO c)) -> b ->
CodeGenFunction r c
call' fvaluePtr x = do
f <- load fvaluePtr
listPtr <- getElementPtr fvaluePtr (1 :: Word32, ())
-- let _ = listPtr :: Value (Ptr (LLNodePtr a))
llnodePtr <- load listPtr
call f llnodePtr x
Souffle/LLVM.hs:58:0:
Couldn't match expected type `Ptr a'
against inferred type `LLNodePtr a -> b -> IO c'
Expected type: LLNodePtr a -> b -> IO c
Inferred type: Ptr (LLNodePtr a -> b -> IO c) -> b1
When using functional dependencies to combine
CallArgs (a -> b) (Value a -> b') r,
arising from the dependency `g -> r f'
in the instance declaration at <no location info>
CallArgs
(LLNodePtr a -> b -> IO c)
(Value (Ptr (LLNodePtr a -> b -> IO c))
-> b
-> CodeGenFunction r c)
r,
arising from a use of `call' at Souffle/LLVM.hs:65:4-21
When generalising the type(s) for `call''
I'm not sure when to typecast to () and back here?
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://projects.haskell.org/pipermail/haskell-llvm/attachments/20111118/5d4e560d/attachment-0001.htm>
More information about the Haskell-llvm
mailing list