This is a precedence issue. You have two infix operators here, :
and $
. As an infix operator, :
has higher precedence than $
, so it binds more tightly. You can ask about precedence in ghci
>> :i :
data [] a = ... | a : [a] -- Defined in `GHC.Types`
infixr 5 :
>> :i $
($) :: (a -> b) -> a -> b
infixr 0 $
The infixr
means that the operator groups to the right (so that the expression a + b + c
is interpreted as a + (b + c)
) and the number gives the precedence (higher = more tightly binding).
Also, you need to know that function application has the highest precedence (tighest binding). So in your two expressions, this one
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
is grouped like
fibs = 0 : (1 : (zipWith (+) fibs (tail fibs)))
whereas this
fibs = 0 : 1 : zipWith (+) fibs $ tail fibs
is grouped like
fibs = (0 : (1 : (zipWith (+) fibs))) $ (tail fibs)
which gives you an error, because the expression to the left of $
should be a function, but in your case it is a list.