[Haskell-cafe] Parsec and type level numerals

brian brianchina60221 at gmail.com
Sat Dec 13 14:45:58 EST 2008


2008/12/13 Nathan Bloomfield <nbloomf at gmail.com>:
> I want to be able to parse a string of digits to a type level numeral as
> described in the Number parameterized types paper.

Hi, I'm at UA too (bsl04). Here's a quick try. Sorry if I'm not
getting what you're doing.

import Text.Parsec
import Text.Parsec.String

data PeanoNumber = Zero | Succ PeanoNumber
  deriving Show

parseP :: Parser PeanoNumber
parseP = do
  char '1'
  rest <- parseP
  return $ Succ rest
  <|> return Zero

test = parseTest parseP "111"


More information about the Haskell-Cafe mailing list