so I've looked around for hours and can't find an answer to match what I need, although many are along the same line so I'm sorry if this is somehow a repost.
In haskell, I have this
shapeToPicture :: Shape -> Picture
shapeToPicture (Line p1 p2) = polyline [p1, p2]
shapeToPicture (Rectangle x y) = solidRectangle x y
shapeToPicture (Polygon [points]) = solidPolygon [points]
shapeToPicture (Polygon []) = solidPolygon []
shapeToPicture (Polygon x) = solidPolygon x
shapeToPicture (Ellipse a b) = scaled(solidCircle(1), a, b)
shapeToPicture (Circle a b) = (solidCircle (a, b))
and the Polygon and Line one's will compile, but Rectangle, Circle, and Ellipse will have the error message
src/View.hs:46:57: error:
• Couldn't match type ‘(Double, Double)’ with ‘Double’
Expected type: Double
Actual type: Coords
• In the second argument of ‘solidRectangle’, namely ‘b’
In the expression: (solidRectangle a b)
In an equation for ‘shapeToPicture’:
shapeToPicture (Rectangle a b) = (solidRectangle a b)
|
46 | shapeToPicture (Rectangle a b) = (solidRectangle a b)
| ^
Failed, two modules loaded.
I know I have a constructor 'Rectangle' which takes coords, and a codeworld function 'solidRectangle' which takes a Double, but I don't know how to match those so that the code will compile. This message is the same for Circle and Ellipse for the same reason.
note: this is how the constructors are defined
type Coords = (Double, Double)
data Shape
= Line Coords
Coords
| Polygon [Coords]
| Rectangle Coords
Coords
| Circle Coords
Coords
| Ellipse Coords
Coords
deriving (Show)
Thank you.