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 8732565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:27:44+00:00 2026-06-13T09:27:44+00:00

Here is my ADT: type Color = String type Hight = Integer type Width

  • 0

Here is my ADT:

type Color = String
type Hight = Integer
type Width = Integer
type Des = String -- description 

data Shape = Shape Color [(Hight, Width)] Des
         deriving(Show)

I would like to define a function called, confirm:

confirm::Restriction->Shape->Bool

where:

false::Restriction -- the restriction fails

and

greater::Integer->Restriction --height or width is greater than given number

I need help defining Restriction, confirm, false and greater

  • 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-06-13T09:27:45+00:00Added an answer on June 13, 2026 at 9:27 am

    The data type Restriction should be Shape -> Bool.
    you don’t then need confirm, and you can use False instead of false.

    I’ve renamed greater to notTooBig because then it’s true when the data’s OK. I feel that makes more sense.

    notTooBig:: Shape -> Bool
    notTooBig n (Shape _ dimensions _) = all smallenough dimensions where
      smallenough (h,w) = h <=n && w <= n
    

    The _ means ignore this bit – we don’t need the colour or description.


    edit: It seems to be very important for you to have

    confirm::Restriction->Shape->Bool
    

    and

    false::Restriction -- the restriction fails
    

    so let’s make a data type Restriction to suit you:

    data ARestriction = ColourR (Colour -> Bool) -- (sorry I can't resist using British spelling)
                      | HeightR (Height -> Bool) -- (Hight is surely a typo)
                      | WidthR  (Width -> Bool)
                      | DesR    (Des -> Bool)
    type Restrictions = [ARestriction]
    

    so for example, you could have [ColourR (=="red"), WidthR (>7)] which would only allow red things wider than 7.

    confirm1 :: ARestriction -> Shape -> Bool
    confirm1 (ColourR check) (Shape c ds d) = check c
    confirm1 (HeightR check) (Shape c ds d) = all check $ map fst ds
    confirm1 (WidthR check) (Shape c ds d) = all check $ map snd ds
    confirm1 (DesR check) (Shape c ds d) = check d
    
    confirm :: Restrictions -> Shape -> Bool
    confirm rs s = all (flip confirm1 s) rs
    

    anyway, we can use this like this:

    confirm [ColourR (=="red"), WidthR (>7)] (Shape "red" [(2,3),(3,4)] "square")
    

    which gives you True.

    You also wanted to define false, but let’s try true first:

    true :: Restrictions
    true = []
    

    This works because all of the restrictions in the list are satisfied.

    You can also define

    false :: Restrictions
    false = ColourR (const False)
    

    which checks the colour of a shape, but constantly tells you False.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my ADT: data Tree a = Val Integer |Tree a |Variable a
Here's my ADT: data Ex a = I Integer --integer | Add (Ex a)
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Every One Here When i update my ADT plugin to ADT 16 i get
Here is my problem: I'm building an AIR package, using the mxmlc and adt
Several of my Android applications show the following type message in the logcat output:
Here's an exerpt from the ADT's latest changelog: Build performance improvements. The big changes
I followed the instructions here: http://developer.android.com/sdk/eclipse-adt.html#installing but the installation froze, so I stopped it

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.