# Parser Combinators via Transformers

```
{-# OPTIONS -Wall -fwarn-tabs -fno-warn-type-defaults #-}
module ParserTrans (GenParser, Parser,
getC,
choose,
(<|>),
satisfy,
doParse,
) where
import Control.Monad.List
import Control.Monad.State
```

Recall the generalized parser type from homework 5. It looks familiar, right?

`newtype GenParser e a = P ([e] -> [(a, [e])])`

Your job in this problem is to replace the newtype definition above with a type defined using monad transformers. You'll then need to update the definitions in the rest of this file to correspond to your new type definition.

After you finish this translation, you can test it using your solution from homework 5. You should be able to replace `import Parser`

with `import ParserTrans`

at the top of your version of ParserCombinators.hs and Main.hs. The only other change that you'll need to make to these files is due to the fact that the `get`

function from the previous version of the file has been renamed to `getC`

here so that it doesn't conflict with the `get`

operation of the `MonadState`

type class.

`type Parser a = GenParser Char a`

```
doParse :: GenParser e a -> [e] -> [(a,[e])]
doParse p s = undefined
```

The `getC`

function was called `oneChar`

in lecture and `get`

in HW5.

```
-- | Return the next character
getC :: GenParser e e
getC = undefined
-- | Return the next character if it satisfies the given predicate
-- (this was called satP in lecture)
satisfy :: (e -> Bool) -> GenParser e e
satisfy p = do c <- getC
if (p c) then return c else fail "End of input"
-- | Combine two parsers together in parallel, producing all
-- possible results from either parser.
choose :: GenParser e a -> GenParser e a -> GenParser e a
choose = undefined
-- | Combine two parsers together in parallel, but only use the
-- first result. This means that the second parser is used only
-- if the first parser completely fails.
(<|>) :: GenParser e a -> GenParser e a -> GenParser e a
p1 <|> p2 = undefined
```

## News :

Welcome to CIS 552!

See the home page for basic
information about the course, the schedule for the lecture notes
and assignments, the resources for links to the required software
and online references, and the syllabus for detailed information about
the course policies.