『 Learn You a Haskell For Great Good』の部分関数の章には、次のコードが含まれています。
multThree :: (Num a) => a -> a -> a -> a
multThree x y z = x * y * z
ghci> let multTwoWithNine = multThree 9
ghci> multTwoWithNine 2 3
54
ghci> let multWithEighteen = multTwoWithNine 2
ghci> multWithEighteen 10
180
私は現在Pythonのfunctoolsライブラリで遊んでおり、それを使用してそれらの関数の動作を複製することができました。
from functools import partial
def multThree(x,y,z):
return x * y * z
>>> multTwoWithNine = partial(multThree,9)
>>> multTwoWithNine(2,3)
>>> multWithEighteen = partial(multTwoWithNine,2)
>>> multWithEighteen(10)
180
私が今やりたいことの1つは、同じ本の章から、次のような、より興味深い高階関数のいくつかを複製できるかどうかを確認することです。
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith' _ [] _ = []
zipWith' _ _ [] = []
zipWith' f (x:xs) (y:ys) = f x y : zipWith' f xs ys
partial()
ただし、これを行う方法がわかりません。また、ここで役立つかどうかもわかりません。