据我所知,Haskell没有全局状态,所以有没有办法编写一个函数f,它将返回f(n - 1)+ 1,其中n是函数调用的数量,f(1)= 0.
它不应该接受任何参数并使用像 func f
Prelude> f ()
0
Prelude> f ()
1
Run Code Online (Sandbox Code Playgroud) 我有以下数据
data A = C1 String | A :@: A
deriving(Show)
app inp = case inp of
a1 :@: a2 -> (C1 "a") :@: (C1 "b")
_ -> C1 "c"
Run Code Online (Sandbox Code Playgroud)
为什么案例会返回输入而不是(C1 "a") :@: (C1 "b")?
*Test> app (C1 "c") :@: (C1 "d")
C1 "c" :@: C1 "d"
Run Code Online (Sandbox Code Playgroud)
如果我改变A :@: A,工作正常C2 A A