[Haskell-cafe] Those damned parentheses

Eitan Goldshtrom thesourceofx at gmail.com
Sat May 7 21:10:18 CEST 2011


Hi. I am kind of tired of all of the parentheses I have to put in places 
and I'm trying to figure out what is the correct way to write code such 
that I can leave out parentheses. For example, I have the following:

data Message = ... --leaving this out because it's not important
data Plane = Plane {
   id          :: Int,
   position    :: (Int,Int,Int),
   direction   :: Int,
   path        :: [Int],
   messagebuf  :: Chan Message
   }

main = do
   c <- newChan :: Chan Message
   p <- Plane 0 (0,0,0) 0 [] c
   f p

f p = putStrLn $ (show Main.id p) ++ " - message received"

This causes an error "The function `show' is applied to two arguments". 
If I put instead:
f p = putStrLn $ (show . Main.id p) ++ " - message received"

I get the error "Couldn't match expected type `[Char]' with actual type 
`a0 -> c0'". The only way it seems to work is
f p = putStrLn $ (show (Main.id p)) ++ " - message received"

This seems to be the same for many other situations where I try to use 
function composition of some sort. It's just getting kind of annoying.

-Eitan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110507/e679087c/attachment.htm>


More information about the Haskell-Cafe mailing list