tags:

views:

151

answers:

1

Quick question I've encountered while getting my feet under me in Haskell related to this quick test:

module Main where
main :: IO()
main = putStrLn (show (inc 3))

inc :: (Num a) => a -> a
inc x = x+1

Is there a better way to output the value of the inc function? I could not get output without using nested parens to force evaluation order. With fewer parens I receive type errors. Just figure there must be a better way.

Thanks if you can clear my head :)

+12  A: 

First of all: parentheses don't force evaluation order.

To get rid of parentheses you can use $ which has very low precedence and thus allows you to get rid of parentheses for the last argument.

For this particular case there's also the print function which is defined as putStrLn . show, so you can do print (inc 3) or print $ inc 3.

sepp2k
A great help, much obliged. It's always the simple things that get me :)