module Main where ls = [1,2,3,4,5] main = do printList ls putStr "last element: " --. (++ (last ls)) . (++"\n") putStr "2nd element:" --. (++ (ls !! 1)) . (++"\n") putStr "number of elements in the list: "-- . (++ length ls) --reverse the list reverse ls putStrLn "Reverse List:" printList ls -- putStrLn "list reversed: " ls printList::[list]->() printList [list] = () i = 0 putStr "[" loop = do putStr list !! i i = i + 1 if i > (length list) - 1 then --when reached end, put a newline then return putStrLn "]" else putStr "," loop
Gives me error:
exercises.hs:8:3: parse error on input `putStr'
[1 of 1] Compiling Main ( exercises.hs, interpreted )
Failed, modules loaded: none.
I'm not sure what's happening, putStr is a real function, is it not?


Sign In
Create Account

Back to top










