我正在学习 FP 并且在玩过 GHCi 后有一些困惑。
假设我有两个简单的功能:
twice :: (a -> a) -> (a -> a)
twice f a = f (f a) -- Equation 1
double :: Int -> Int
double = \x -> x * 2
Run Code Online (Sandbox Code Playgroud)
分解评估twice twice twice double 3(注意 3x twice+1x double),我会:
{-
twice twice twice double 3
== (twice twice twice double) 3
== (twice twice (twice double)) 3
== (twice (twice (double double 3)))
== (twice ((double double) (double double 3))) …Run Code Online (Sandbox Code Playgroud)