Note that there are some explanatory texts on larger screens.

plurals
  1. POcheck if element exists on the sub-list
    primarykey
    data
    text
    <p>I can have many Figures on my list. Each Figure can have many Rectangles on its list. I have a problem with my function checkNewRectangleId - this function should ask user about new rectangle id until he write really new id and then it should return this id - but I have an error: couldn't match expected type IO t against inferred type Maybe figureType line <code>(Figure id width height rectangles) &lt;- findFigure idFigure x</code> in my function - could you help ?</p> <pre><code>import IO import Char import System.Exit import Maybe import Data.Time.Calendar import System.Time checkNewRectangleId :: Int -&gt; [FigureType] -&gt; IO Int checkNewRectangleId idFigure x = do idRectangle &lt;- getInt "Give me new rectangle id: " (Figure id width height rectangles) &lt;- findFigure idFigure x if isJust (findRectangle idRectangle rectangles) then do putStrLn ("We have yet rectangle with id " ++ show idRectangle) checkNewRectangleId idFigure x else return idRectangle data FigureType = Figure Int Int Int [RectangleType] deriving(Show, Read) data RectangleType = Rectangle Int CalendarTime deriving(Show, Read) findFigure :: Int -&gt; [FigureType] -&gt; Maybe FigureType findFigure _ [] = Nothing findFigure n ((Figure id width height rectangles) : xs) = if n == id then Just (Figure id width height rectangles) else findFigure n xs findRectangle :: Int -&gt; [RectangleType] -&gt; Maybe RectangleType findRectangle _ [] = Nothing findRectangle n ((Rectangle id date) : xs) = if n == id then Just (Rectangle id date) else findRectangle n xs isInt i = not (null i) &amp;&amp; all isDigit i getInt :: String -&gt; IO Int getInt q = do putStr q; i &lt;- getLine if isInt i == False then do putStrLn "Bad number" getInt q else return (read i) </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.
    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