如果我将以下2行放入foobar.hs
f 1 = 1
f x = f (x-1)
Run Code Online (Sandbox Code Playgroud)
然后
$ ghci
> :load foobar.hs
> f 5
1
Run Code Online (Sandbox Code Playgroud)
但如果我这样做
$ ghci
> let f 1 = 1
> let f x = f (x-1)
> f 5
^CInterrupted.
Run Code Online (Sandbox Code Playgroud)
然后它不会返回.为什么?
后一种绑定优先于前者.在ghci中使用它:
Prelude> :{
Prelude| let f 1 = 1
Prelude| f x = f (x-1)
Prelude| :}
Prelude> f 5
1
Run Code Online (Sandbox Code Playgroud)
或者,没有布局:
Prelude> let f 1 = 1; f x = f (x-1)
Prelude> f 5
1
Run Code Online (Sandbox Code Playgroud)