Note that there are some explanatory texts on larger screens.

plurals
  1. POType error in Haskell program
    primarykey
    data
    text
    <p>User can give id, width, height and description rectangle and then I write it to a file. Now I would like to load this content from the file to my program but I have error: </p> <p>Couldn't match expected type [RectangleType] against inferred type IO [Rectangletype]. In the first argument of menuRectangles namely db. In the expression menuRectangles db. In a do expression menuRectangles db. </p> <p>What is going on ? This is content of my file: [Rectangle 2 5 6 "abcabc",Rectangle 1 2 4 "abcabc"]</p> <p>This is code:</p> <pre><code>import IO import Char import System.Exit import Maybe data RectangleType = Rectangle Int Int Int deriving(Show, Read) loadFile :: FilePath -&gt; IO [RectangleType] loadFile fname = catch (do fileContent &lt;- readFile fname return (read fileContent) ) errorHandler where errorHandler e = do putStrLn ("Error file") exitFailure db = loadFile "db.txt" main = do putStrLn "Choose option:" n &lt;- getLine case n of "1" -&gt; do menuRectangles db; main "2" -&gt; putStrLn "bye, bye" otherwise -&gt; do putStrLn "Bad option"; main menuRectangles :: [RectangleType] -&gt; IO [RectangleType] menuRectangles rs = do putStrLn "Please choose option:" putStrLn "1 - Add rectangle" putStrLn "2 - Show rectangle" putStrLn "3 - Quit" putStr "Number: " n &lt;- getLine case n of "1" -&gt; do { {- rs_new &lt;- addRectangle rs; -} menuRectangles rs }; "2" -&gt; do { {- showRectangle rs; -} menuRectangles rs } "3" -&gt; do { putStrLn "Quitting"; return rs } otherwise -&gt; do { putStrLn "The End"; return rs } </code></pre> <p><strong>EDIT: correct code:</strong></p> <pre><code>import IO import Char import System.Exit import Maybe data RectangleType = Rectangle Int Int Int deriving(Show, Read) loadFile :: FilePath -&gt; IO [RectangleType] loadFile fname = catch (do fileContent &lt;- readFile fname return (read fileContent) ) errorHandler where errorHandler e = do putStrLn ("Error file") exitFailure main = do db &lt;- loadFile "db.txt" mainMenu db mainMenu rs = do putStrLn "Choose option:" n &lt;- getLine case n of "1" -&gt; do menuRectangles rs; mainMenu rs "2" -&gt; putStrLn "bye, bye" otherwise -&gt; do putStrLn "Bad option"; mainMenu rs menuRectangles :: [RectangleType] -&gt; IO [RectangleType] menuRectangles rs = do putStrLn "Please choose option:" putStrLn "1 - Add rectangle" putStrLn "2 - Show rectangle" putStrLn "3 - Quit" putStr "Number: " n &lt;- getLine case n of "1" -&gt; do { {- rs_new &lt;- addRectangle rs; -} menuRectangles rs }; "2" -&gt; do { {- showRectangle rs; -} menuRectangles rs } "3" -&gt; do { putStrLn "Quitting"; return rs } otherwise -&gt; do { putStrLn "The End"; return rs } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload