Mercurial > 12ws.info2
comparison exercises/src/AdditionParser.hs @ 29:53732b9605c7
add AdditionParser
author | Markus Kaiser <markus.kaiser@in.tum.de> |
---|---|
date | Fri, 11 Jan 2013 00:49:48 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
28:e0ae5d8b55d3 | 29:53732b9605c7 |
---|---|
1 module AdditionParser where | |
2 | |
3 import Data.Char | |
4 import Parser | |
5 | |
6 digit :: Parser Char Char | |
7 digit = one isDigit | |
8 | |
9 number :: Parser Char String | |
10 number = list1(one isDigit) | |
11 | |
12 addition :: Parser Char [String] | |
13 addition = number *** optional (item '+' *** addition >>> snd) >>> ints | |
14 where | |
15 ints (x, Just y) = x : y | |
16 ints (x, _) = [x] | |
17 | |
18 test = addition "2134+123+1+2+3" |