小编Tua*_*uan的帖子

Haskell 高阶函数和结合性

我正在学习 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)

haskell functional-programming ghc higher-order-functions

3
推荐指数
1
解决办法
88
查看次数