如何在haskell中解析parsec表达式

时间:2015-12-07 22:30:10

标签: haskell parsec

类型:

data Type
  = Ttype 
  | Arr Type Type
  deriving (Eq, Show)

data Ttype = String  

我的代码:

lchar = lexeme . char

parens :: ParserT a b -> ParserT a b
parens = between (lchar '(') (lchar ')')

symbol :: String -> ParserT a String
symbol p = string p <* spaces

typeParser :: CharParser () Type
typeParser = arr <|> tbool <|>  tbool
  where tbool =  Ttype <$> (show tbool)
        subtyp = parens arr <|> tbool <|> tbool
        arr = chainr1 subtyp $ try (symbol "->" *> pure Arr)
parseIt :: String -> Either ParseError Type
parseIt  = P.parse typeParser ""

如何解析此类型:(A->(B-> C)) - &gt;(A-> B) 抱歉。我是Haskell语言的新手。

0 个答案:

没有答案