I try to develop a simple average function in Haskell.
This seems to work:
lst = [1, 3]
x = fromIntegral (sum lst)
y = fromIntegral(length lst)
z = x / y
But why doesn’t the following version work?
lst = [1, 3]
x = fromIntegral.sum lst
y = fromIntegral.length lst
z = x / y
You’re getting tripped up by haskell’s precedence rules for operators, which are confusing.
When you write
Haskell sees that as the same as:
What you meant to write was: