Haskell IO: Konvertiert einen IO-String in einen anderen Typ
Ich habe ein Haskell-Programm, das eine Datei als Eingabe verwendet und in einen binären Suchbaum konvertiert.
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
Wenn ich jedoch den folgenden Befehl ausführe:
ins 5 fileRead
Ich habe folgende Fehlermeldung erhalten:
<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
Kann mir bitte jemand helfen?
Vielen Dank