Haskell 是一种函数式编程语言。

笔记

printf debugging

import Debug.Trace
 
dbg :: Show a => String -> a -> a
dbg msg x = trace (msg ++ " " ++ show x) x

使用方法:把变量 x 换成 (dbg "x =" x)

letwhere

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}

3

另见

外部链接

Footnotes

  1. https://stackoverflow.com/q/4362328/10974106

  2. A Gentle Introduction to Haskell 4.5 Lexical Scoping and Nested Forms

  3. https://neilmitchell.blogspot.com/2019/01/ignoring-hlint.html