The signatures of show
and read
are as follows:
show :: Show a => a -> String
read :: Read a => String -> a
The problem is that in your program, Haskell can not infer the type of data read, since these are used as arguments of f :: [a] -> [[a]] -> [(a,a)]
. You simply know that the first data is a list of something , the second data is a list of lists of something , and that it returns a list of tuples of something and something Therefore, you do not know how to read your data with read
and you do not know how to show the result with show
.
To solve this you must provide a type annotation for the read
function:
putStrLn (show (f (read xs :: [Int]) (read ys)))
In this case it would be enough to write down one of the data, since the function f
has only one variable of type, a
, and if the first data is a list of integers, you can infer that the second one is a list of integer lists.
However, if the signature of f
were this:
f :: [a] -> [[b]] -> [(a,b)]
You should write down the type of the two data:
putStrLn (show (f (read xs :: [Int]) (read ys :: [[Char]])))