I'm supposed to take this code:
f x y z = x^3 - g (x + g (y - g z) + g (z^2))
where g x = 2*x^2 + 10*x + 1
And rewrite it without where (or let).
They mean to write it with a Lambda function (\x ->...)
I'm trying to reuse a Lambda function on Haskell. Any ideas?
As bravit hints at, you can rewrite a non-recursive let
using a lambda in the following way:
let x = A in B ==> (\x -> B) A
where x
is a variable and A
and B
are expressions.
To reuse something you can make it an argument to something.
I think the intention is what bravit hints at.
The smartypants follow-the-letters-of-the-law workaround is binding g
with a case
;)
To expand on hammar's and bravit's hints, your solution is going to require not just one lambda, but two - one of which will look a great deal like g
, and the other of which will look a great deal like the second half of f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With