$30
Outline
● Higher-order functions and lists in Haskell recap
● Adding user’s numbers
● Exercise: N-body simulation
Adding user’s numbers
Exercise 6.1.
Implement a program sumOfTwoInputs that reads two integers from standard input and prints their sum.
Exercise 6.2.
Implement a program sumOfManyInputs that reads a number N followed by N integers from standard input and prints their sum.
Running a one-question test
Exercise 6.3.
Design types Question and Answer, and implement a function runQuestion :: Question -> IO Answer
that asks the question to the standard output and collects a numeric answer from the standard input. What should the program do when no answer is given? Modify the type of runQuestion accordinly.
Running a full test
Exercise 6.4.
Implement a function runQuestions that runs a series of questions and collects answers for all of them.
Exercise 6.5.
Design types Test and TestAnswers, and implement a function runTest :: Test -> IO TestAnswers
that asks runs a test (a series of questions) and collects a user answers from the standard input.
Introducing more types of questions
Exercise 6.6.
Extend types Question and Answer to support True-or-False questions.
Exercise 6.7.
Extend types Question and Answer to support multiple choice questions.
Exercise 6.8.
Extend types Question and Answer to support free text responses.