When I write only main = do ... block, it works perfectly. When I put only stories = do... block it also works. Maybe there is an indentation problem.
Here is the code:
stories = do
let str0 = "There once was "
str1 <- ["a princess ", "a cat ", "a little boy "]
let str2 = "who lived in "
return ( str0 ++ str1 )
main = do
let len = length stories
putStrLn ("Enter a number from 0 to " ++ show (len - 1))
n <- readLn
putStrLn ""
putStrLn (stories !! n)
What is wrong with it?