beginner haskeller here. trying represent pizza equation simple command line program takes number of people , returns appropriate number of pizzas order. know need convert input (io string
) int , convert result string using show
. how io string -> int
? or skinning cat wrong?
import system.environment import system.io pizzas :: integral => -> pizzas x = div (x * 3) 8 main = putstrln "how many people going feed?" arg <- getline -- arg needs io string -> int -- apply pizzas function -- int -> string putstrln "you need order " ++ string ++ " pizzas."
using read convert type string appropriate type if possible
and using show convert integer it's string representation
arg <- getline let num = pizzas (read arg) putstrln $ "you need order " ++ (show num) ++ " pizzas."
or this:
arg <- readln :: io int let num = pizzas arg putstrln $ "you need order " ++ (show num) ++ " pizzas."