CS 119 Lab 11 – Monads
Objectives
Perform the following tasks in the order given.
| Assignment: Write a function rollNDice :: Int -> Random [Int] that rolls dice n times and returns a list of n results. Do this with >>= and return. |
sumNDice :: Int -> Seed -> Int
sumNDice n seed = foldl1 (+) (fst (apply (rollNDice n) seed))
This function takes the first item from
the pair in the result, which is the list of rolls, and adds them up using
the higher order function foldl1.