File: WorldCup.curry

package info (click to toggle)
curry-tools 1.0.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,492 kB
  • ctags: 121
  • sloc: makefile: 470; sh: 421
file content (23 lines) | stat: -rw-r--r-- 630 bytes parent folder | download
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))