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 🙂
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
printfunction which is defined asputStrLn . show, so you can doprint (inc 3)orprint $ inc 3.