我正在阅读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)
Run Code Online (Sandbox Code Playgroud)
我很难理解最后一行
where g a b c = (a,c)
Run Code Online (Sandbox Code Playgroud)
我知道这一行存在是因为三行有类型Parser(Char,Char)但gabc代表什么?gabc语法有效吗?我习惯于在某些情况下看到
f :: s -> (a,s)
f x = y
where y …Run Code Online (Sandbox Code Playgroud)