CS计算机代考程序代写 — CPSC 312 – 2021 – Interactive accumulator

— CPSC 312 – 2021 – Interactive accumulator
— Copyright D. Poole 2021 released under the GPL.

module IOAdder2 where

— To run it, try:
— ghci
— :load IOAdder2
— goi
— go

ask q =
do
putStr q
line <- getLine return line accum n = do line <- ask ("Total " ++ show n ++ "\nInput a number (exit with 0): ") let val = read line if (val==0) then return n else accum (n+val) goi :: IO Integer goi = accum 0 go :: IO Double go = accum 0