Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4539208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:54:55+00:00 2026-05-21T14:54:55+00:00

I can have many Figures on my list. Each Figure can have many Rectangles

  • 0

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 (Figure id width height rectangles) <- findFigure idFigure x in my function – could you help ?

import IO
import Char
import System.Exit
import Maybe
import Data.Time.Calendar
import System.Time


checkNewRectangleId :: Int -> [FigureType] -> IO Int
checkNewRectangleId idFigure x  = do
    idRectangle <- getInt "Give me new rectangle id: "
    (Figure id width height rectangles) <- 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 -> [FigureType] -> 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 -> [RectangleType] -> 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) && all isDigit i

getInt :: String -> IO Int
getInt q = do
    putStr q;
    i <- getLine
    if isInt i == False then do
            putStrLn "Bad number"
            getInt q
        else return (read i)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:54:55+00:00Added an answer on May 21, 2026 at 2:54 pm

    Since you say idFigure is guaranteed to exist, you can use fromJust in the Data.Maybe module to convert a Maybe FigureType into a FigureType:

    let (Figure id width height rectangles) = fromJust $ findFigure idFigure x
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Each book can have many authors. And each author can author many books. class
I have a product, and a product can have many images. This is through
I have a customers table, and an orders table. Each customer can have many
I'm trying to figure out how to do this: I have a list of
We can have many handlers: touches handler, UIControl handler (buttons, sliders), performSelector, CADisplayLink, NSTimer
Summary A parent can have many children. How do you write a service such
I have a class that I can have many instances of. Inside it creates
I have models Product and Category . Category can have many products. ( Product
I have 2 entities a Department and an Employee. 1 Department can have many
EDIT: my revised Entity relationship diagram A Student can have many contact times but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.