小编sch*_*uss的帖子

块的语法

我正在阅读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)

syntax haskell notation

2
推荐指数
1
解决办法
117
查看次数

标签 统计

haskell ×1

notation ×1

syntax ×1