All pastes #442725 Raw Edit

Stuff

public text v1 · immutable
·published 2007-04-16 12:59 UTC
rendered paste body
module Main
	where

import IO

main = do
	hSetBuffering stdin LineBuffering
	nums <- getNumbers
	putStrLn ("The sum is " ++ (filtr (+) 0 nums))
	putStrLn ("The product is " ++ (filtr (*) 1 nums))
	printFactorials nums

factorial 0 = 1
factorial 1 = 1
factorial 2 = 2
factorial n = n * factorial (n-1)

printFactorials (x:xs) =
	putStrLn (x ++ " factorial is " ++ (factorial x))
	printFactorials xs	
	
getNumbers = do
	putStrLn "Give me a number (or 0 to stop):"
	my_line <- getLine
	let my_nbr = read my_line
	-- Test.hs:27:1: Parse error in pattern
	if my_line == 0
		then
			return []
		else
			rest <- getNumbers
			return (my_nbr : rest)