1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=defaultrules #-}
{-# OPTIONS_CYMAKE -Wnone #-}
import Test.EasyCheck
-- Example: parse World Cup soccer scores (e.g., "_:_", "3:2")
import Char(isDigit)
parse (team1++" _:_ "++team2) = (team1, team2, Nothing)
parse (team1++[' ',x,':',y,' ']++team2)
| isDigit x && isDigit y
= (team1, team2, Just (toInt x,toInt y))
parse'default _ = error "Wrong format!"
toInt :: Char -> Int
toInt c = ord c - ord '0'
main = [parse "GER _:_ USA",
parse "GER 1:0 USA"]
test1 = parse "GER _:_ USA" -=- ("GER","USA",Nothing)
test2 = parse "GER 1:0 USA" -=- ("GER","USA",Just (1,0))
|