I didn't know how to describe this for the title, but it should be understandable with the example code. How can I shorten this:
parse qs (e@Mark :t@(Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@Mark :t@(Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@(Asgn _) :t@(Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@(Asgn _) :t@(Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@LeftParen :t@(Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@LeftParen :t@(Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@(Adv _ _) :t@(Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@(Adv _ _) :t@(Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@(Verb _ _ _):t@(Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@(Verb _ _ _):t@(Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@(Noun _) :t@(Noun _) :Adv _ f:ss) = parse qs $ e : f t : ss
parse qs (e@(Noun _) :t@(Verb _ _ _):Adv _ f:ss) = parse qs $ e : f t : ss
The list is of type [Token]
(as is qs
, which is used in other definitions), which is my own type. Is it possible to have a sub-type of Token
, covering only Mark
, Asgn _
, LeftParen
, Adv _ _
, Verb _ _ _
and Noun _
, and pattern-match with that?
Edit: definition of 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)