{-# LANGUAGE UnicodeSyntax #-} module ParserDet where import Prelude.Unicode import Control.Monad.State type Parser = State String runParser ∷ Parser a → String → a runParser = evalState anyChar ∷ Parser Char anyChar = do input ← get if null input then error "EOF" else do put $ tail xs return x char ∷ Char → Parser Char char c = satisfy (c ≡) anyChar satisfy ∷ (a → Bool) → Parser a → Parser a satisfy pred p = do tok ← p if pred tok then return tok else error "predicate not met" string ∷ String → Parser () string str = mapM char str >> return () (<|>) ∷ Parser a → Parser a → Parser a p <|> q = do tok ← p if failed p then return tok else q where failed = undefined -- the Parser type is not adequate for intercepting a failed parser, and -- therefore not sufficient to implement the choice operator.