Getting Artsy with Haskell: Understanding Part B
Part B of the assignment has lots of confusing data types! State, Graphics, InteractionOf. Don’t worry! By the end of this activity, you will be a master of Part B in no time!
Understanding State
Consider the State data type:
data State = World
[Graphic]
Tool
ColourName
-
What is the type name of the type constructor in State. What does it do?
-
Give an explanation of each of the component data types. Give an example of each.
We are going to understanding this data type through drawing. Go through the following exercise as a group:
-
Draw a “canvas” on the whiteboard. This is where we will draw pictures.
-
Consider this example of the State data type:
World [Graphic (Line (1.0,1.0) (2.0,2.0)) Cyan (0.0,0.0)] (LineTool Nothing) Cyan
Draw this State on your canvas. Label each of the component parts.
-
Draw any shape you want on your canvas. Write out a corresponding State data type.
-
Write a function called
extractGraphics
, which inputs a State and outputs the[Graphics]
of this State.