Haskell IO: convierte la cadena IO a "Otro tipo"
Tengo un programa Haskell que toma un archivo como entrada y lo convierte en un árbol de búsqueda binario.
import System.IO
data Tree a = EmptyBST | Node a (Tree a) (Tree a) deriving (Show, Read, Eq)
ins :: Ord a => a -> (Tree a) -> (Tree a)
ins a EmptyBST = Node a EmptyBST EmptyBST
ins a (Node p left right)
| a < p = Node p (ins a left) right
| a > p = Node p left (ins a right)
| otherwise = Node p left right
lstToTree :: Ord a => [a] -> (Tree a)
lstToTree = foldr ins EmptyBST
fileRead = do file <- readFile "tree.txt"
let a = lstToTree (conv (words file))
return a
conv :: [String] -> [Int]
conv = map read
Sin embargo, cuando ejecuto el siguiente comando:
ins 5 fileRead
Tuve el siguiente error:
<interactive>:2:7:
Couldn't match expected type `Tree a0'
with actual type `IO (Tree Int)'
In the second argument of `ins', namely `fileRead'
In the expression: ins 5 fileRead
In an equation for `it': it = ins 5 fileRead
Por favor alguien me puede ayudar?
Gracias