8. Walk I
A sequence of short exercises to become familiar with the first half of constructors.
- Make
AListmean[Int].
- Write a function (
ao) that takes in an AList and puts out an Int. Theaofunction adds up all of the odd numbers in the list. Include signature.
- Make
WP(for “word pair”) mean(String, String).
- Write a function (
ce) counting how many times the two strings are equal in a list ofWP. Include signature.
- Make a data type called
Celsiusthat holds a Float measuring the temperature.
- Make a similar data type called Fahrenheit.
- (
tempchange) Make a function that convertsCelsiustoFahrenheitaccording to the rule (f = 9/5 c + 32).
- Names: Surname is a String, and GivenName is a String. Make two data types, one for each.
- The
marryfunction takes two Surname and combines them with a hyphen to create a new Surname. Write the signature and function.
-
Beginning with the
Pointdefinition below, write ad0function measuring the distance to the origin.data Point = Origin | Point Float Float
- Make a datatype
Drinkwhich isWaterorGatorade.
- Make a calories function that converts Drink to Int calories. Water is 0, Gatorade is 15. Include a signature.