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
The data type Restriction should be
Shape -> Bool.you don’t then need
confirm, and you can useFalseinstead offalse.I’ve renamed
greatertonotTooBigbecause then it’s true when the data’s OK. I feel that makes more sense.The
_means ignore this bit – we don’t need the colour or description.edit: It seems to be very important for you to have
and
so let’s make a data type
Restrictionto suit you:so for example, you could have
[ColourR (=="red"), WidthR (>7)]which would only allow red things wider than 7.anyway, we can use this like this:
which gives you
True.You also wanted to define
false, but let’s trytruefirst:This works because all of the restrictions in the list are satisfied.
You can also define
which checks the colour of a shape, but
constantly tells youFalse.