Haskell I/O Functions - Programmers Heaven

Howdy, Stranger!




Haskell I/O Functions

What i want to do it's a program that when i write couple of lines with 2 numbers each (games results) like :

1 4
1 1
3 1
3 3
2 1
4 0

it gives

2 (number of games untill victory)


1 4
2 3
2 2

it gives

didn't win yet

what i've done is

gamesUntillVictory :: IO ()
gamesUntillVictory =
text <- getContents
xss :: [String]
xss = lines text
xsss :: [[String]]
xsss = [words x | x <- xss]
yss :: [(Int,Int)]
yss = [toEvens y | y <- xsss]
if ( games yss == length yss)
putStrLn "didn't win yet"
putStrLn (show (games yss))

toEvens :: [String] -> (Int,Int)
toEvens xs = (read (head xs), read (last xs))

games :: [(Int,Int)] -> Int
games [] = 0
games ((k,v):ys)
| k > v = 0
| otherwise = 1 + games ys

and i always get an error that i can't fix.
I would like to know what i did wrong and a possible solution for this problem. Please notice that i've been learning haskell for only one month.

Sign In or Register to comment.