Haskell 是一种函数式编程语言。
笔记
printf debugging
import Debug.Trace
dbg :: Show a => String -> a -> a
dbg msg x = trace (msg ++ " " ++ show x) x使用方法:把变量 x 换成 (dbg "x =" x)。
let 与 where
let 是一个表达式,而 where 不是。where 用于给多个 guard 创建 binding,如下:
f x y
| y > z = ...
| y == z = ...
| y < z = ...
where
z = x * x三个 guard 都可使用 z。用 let 无法达到以上的效果。12
Hlint
Ignore warnings
在 .hlint.yaml 中写:
ignore: {name: Eta reduce}
另见
外部链接
Footnotes
-
A Gentle Introduction to Haskell 4.5 Lexical Scoping and Nested Forms ↩
-
https://neilmitchell.blogspot.com/2019/01/ignoring-hlint.html ↩