Sunteți pe pagina 1din 2

module Excercise1

where
{-
1) Write an I/O program to print something n times (the number of times to outpu
t the
string must be handled as a parameter of the program).
-}
printntime::(String,Int)->IO()
printntime (x,1) = putStr(x)
printntime (x,y) = do
putStr(x)
printntime (x,y-1)
{-
2) Write an I/O program that reads n lines, and then write them in the opposite
order
(reversed).
-}
pSlist::[String]->IO()
pSlist [] = putStrLn "--end"
pSlist (x:xs) = do
putStrLn x
pSlist xs
reverseLine::IO ()
reverseLine= do
putStrLn("enter datas.enter r to finish")
xs<-getLines
pSlist[y|y<-(reverse xs)]
getLines::IO [String]
getLines = do
x<-getLine
if x=="r" then
return ([""])
else
do
y<-getLines
return ((show x):y)
{-
3) Write an I10 program which will read a line of input and test whether the inp
ut is a
palindrome. The program should 'prompt' for its input and also output an appropr
iate
message after testing.
-}
palindrome::IO ()
palindrome = do
putStrLn("enter a worpad to test for palindrome")
x<-getLine
if (isPal(show x)) then
putStrLn("word is palindrome")
else
putStrLn("word is not a palindrome")
isPal::[Char]->Bool
isPal xs = if xs == reverse xs then True
else False
{-
4) Write a program to sum integers supplied one per line until zero is input. Th
e program
should prompt appropriately for its inputs and explain its output.
-}

summer::IO ()
summer = do
putStrLn("enter lines of number to add. finish with 0")
xs<-getInts
putStr("The sum is "++ show(sum xs))
getInts::IO [Int]
getInts = do
x<-getLine
if x=="0" then
return ([0])
else
do
y<-getInts
return ((read x):y)

S-ar putea să vă placă și