Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write return Haskell

Tags:

syntax

haskell

I want my showStackHead function take a stack print the head and return the rests, here is my code --code

showStackHead xx
               | xx == []   = return []
               | otherwise  = do putStrLn("result:" ++ (head xx))
                              return (tail xx)

when I run this code, the compiler tells me there is a parse error about the second return, so what is the right way to write this function?

like image 913
Rn2dy Avatar asked Jun 28 '10 05:06

Rn2dy


1 Answers

Indent the 'return' to the same depth as 'putStrLn', like so:

showStackHead xs
   | xs == []   = return []
   | otherwise  = do putStrLn ("result:" ++ (head xs))
                     return (tail xs)
like image 89
Don Stewart Avatar answered Sep 30 '22 17:09

Don Stewart