我不知道如何描述這個標題,但它應該可以用示例代碼來理解。我怎樣才能縮短這個:如何用許多等效模式縮短Haskell函數定義
parse qs ([email protected] :[email protected](Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected] :[email protected](Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected](Asgn _) :[email protected](Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected](Asgn _) :[email protected](Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected] :[email protected](Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected] :[email protected](Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected](Adv _ _) :[email protected](Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected](Adv _ _) :[email protected](Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected](Verb _ _ _):[email protected](Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected](Verb _ _ _):[email protected](Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected](Noun _) :[email protected](Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs ([email protected](Noun _) :[email protected](Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
名單是[Token]
類型(如qs
,這是在其他定義中使用),這是我自己的類型。是否可能有Token
的子類型,僅涵蓋Mark
,Asgn _
,LeftParen
,Adv _ _
,Verb _ _ _
和Noun _
,並且與該模式匹配?
編輯:的Token
定義:
data Token = (Show, Read a) => Noun a
| Verb String (Token -> Token) (Token -> Token -> Token)
| Adv String (Token -> Token) Token
| Conj String (Token -> Token -> Token) Token
| Name String
| Asgn AsgnType
| Mark
| LeftParen
| RightParen
deriving (Show, Read)
「Token」的完整定義是什麼? –