Reputation: 23
compute fp = do
text <- readFile fp
let (a,b) = sth text
let x = data b
--g <- x
putStr $ print_matrix $ fst $ head $ x
It works when i get only first element but i want do this for all element on the list of pair. When i write g<- x i got Couldn't match expected type `IO t0' with actual type [([[Integer]], [[Integer]])]
Upvotes: 2
Views: 330
Reputation: 11079
You're inside the IO Monad here, so any time you write a "bind" arrow <-
, the thing on the right side has to be an IO operation. So the short answer is, you don't want to use <-
on the value x
.
Now, it looks like you want to call print_matrix for each element of a list rather than a single element. In that case I think Macke is on the right track, but I would use mapM_ instead:
mapM_ (putStr . print_matrix . fst) x
should do the trick.
The reason is that you are explicitly saying you want to putStr
each element, one at a time, but you don't care about the result of putStr
itself.
Upvotes: 3