Previous: LinksUp: Haskell


Table of Contents

1 Operator Precedence

Consider the following:

strSum :: [Int] -> String
strSum xs = show $ sum xs
-- equivalent to
strSum xs = ($) show (sum xs)

This seems strange but it's exactly the same as:

minMax :: [Int] -> Int
minMax xs = minimum xs + maximum xs
-- equivalent to
minMax xs = (+) (min xs) (max xs)

This because function application has higher precedence than any operator, so f a `op` g b is always equivalent to (f a) `op` (g b).

Author: root

Created: 2024-03-23 Sat 11:44