【发布时间】:2017-07-16 06:54:03
【问题描述】:
我正在阅读 Graham Hutton 的《Haskell 编程》,它在第 13 章中给出了以下代码:
import Control.Applicative
import Data.Char
{- some code omitted -}
newtype Parser a = P (String -> [(a, String)])
item :: Parser Char
item = P (\ input -> case input of
[] -> []
x:xs -> [(x,xs)])
three :: Parser (Char,Char)
three = pure g <*> item <*> item <*> item
where g a b c = (a,c)
我很难理解最后一行
where g a b c = (a,c)
我知道这条线的存在是因为三的类型为 Parser(Char, Char) 但 g a b c 代表什么? g a b c 在语法上如何有效?我习惯于看到像这样的情况
f :: s -> (a,s)
f x = y
where y = ... x ...
其中每个符号 x 和 y 出现在 where 声明之前。
【问题讨论】: