[haskell-llvm] Beginner - Anonymous Functions
Elliott Pace
etp20 at cam.ac.uk
Wed Nov 16 13:43:53 GMT 2011
Hi,
Thanks for the pointer in the right direction. I had a think and realised I
was going about it completely the wrong way.
My current attempt (at sum x y z = x + y + z) is that:
A function value is a pointer to a pair of pointers. One pointer being the
code to execute and one pointer being the head of a linked list of
arguments which will then be walked when the body is finally evaluted (here
at sum3).
Here is my attempt:
http://paste.ubuntu.com/740212/
Unfortunately I get the error:
LLVM.hs:1:0:
Couldn't match expected type `a -> a -> b'
against inferred type `Ptr ((a -> a -> b) -> (a -> a -> b) -> b1)'
Expected type: (a -> a -> b) -> b1
Inferred type: Ptr ((a -> a -> b) -> (a -> a -> b) -> b1) -> b2
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
((a -> a -> b) -> b1)
(Value (Ptr ((a -> a -> b) -> (a -> a -> b) -> b1))
-> CodeGenFunction r (Value (Ptr (Ptr ((a -> a -> b) -> b)))))
r,
arising from a use of `call'' at LLVM.hs:71:17-29
What is incorrect with my approach? It seems simple enough but I seem to be
getting type errors.
if again I've done something quite stupid, some documentation/things to
read would be greatly appreciated.
On Sun, Nov 6, 2011 at 10:53 PM, Henning Thielemann <
lemming at henning-thielemann.de> wrote:
>
> On Sun, 6 Nov 2011, Elliott Pace wrote:
>
> I'm a beginner to using Haskell-LLVM and when trying to pull together
>> some toy functions, I came across
>> the following problem. I've looked at the examples but I cannot find
>> something that does this.
>>
>> The idea is to create a curried function (and therefore an anonymous
>> function) ala:
>>
>> plus x y = x + y;
>>
>> My attempt is as below:
>>
>> data Mod = Mod { mplus :: Function (Word32 -> IO (Function (Word32 -> IO
>> Word32)))
>>
>>
>> }
>>
>
> How shall this work on the machine level? It would mean, that 'mplus'
> actually compiles a new function of type (Word32 -> IO Word32) at run-time.
>
> For a real application there are certainly ways to achieve what you want
> in a different way.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://projects.haskell.org/pipermail/haskell-llvm/attachments/20111116/87aa151b/attachment-0001.htm>
More information about the Haskell-llvm
mailing list