Questa domanda mi sembra un po 'curiosa e interessante. Quindi, sto cercando di capire qual è il calcolo lambda, trovare una risposta e voglio mostrarlo a OP (tutti gli hint sono già stati effettivamente mostrati, avviso spoiler).
In primo luogo, proviamo a ridefinire f
:
λ> let f = (\g x y z -> x^3 - g(x + g(y - g z) + g(z^2)))
f ::
(Integer -> Integer) -> Integer -> Integer -> Integer -> Integer
funzione Così, abbiamo, che ottiene i numeri funzione e 3 e restituire la risposta. Utilizzando curring possiamo aggiungere g
definizione proprio qui, come f_new = f g
:
λ> let f = (\g x y z -> x^3 - g(x + g(y - g z) + g(z^2))) (\x -> 2*x^2 + 10*x + 1)
f :: Integer -> Integer -> Integer -> Integer
Abbiamo finito. Controlliamo:
λ> f 0 0 0
-13
La risposta è corretta.
UPD:
In tali esempi let
è solo un modo per dichiarare funzione nell'interprete, quindi risposta finale è:.
f :: Num a => a -> a -> a -> a
f = (\g x y z -> x^3 - g(x + g(y - g z) + g(z^2))) (\x -> 2*x^2 + 10*x + 1)
fonte
2011-11-20 00:09:57
'f = capovolgere capovolgere ((1 +) ap ((+). (2 *). (^ 2)) (10 *)). (Flip .) . ap ((.). (.). (.). (-). (^ 3)) ((ap id.).). flip flip (flip id. (^ 2)). (liftM2 (liftM2 (() id). (.). (.). (+)) ': f fatto senza senso da lambdabot – fuz