mc.robin
mc.robin

Reputation: 179

confused about dot-operator in haskell

(head.group) "1234"

It work.

head.group "1234"

I get errors:

<interactive>:8:6:
Couldn't match expected type `a0 -> [c0]'
            with actual type `[[Char]]'
In the return type of a call of `group'
Probable cause: `group' is applied to too many arguments
In the second argument of `(.)', namely `group "1234"'
In the expression: head . group "1234"

I think (head.group) is same as head.group, why (head.group) work and head.group not.

Upvotes: 0

Views: 220

Answers (1)

Zeta
Zeta

Reputation: 105885

Because

(head . group) "1234" = f "12345"
  where
    f = head . group

whereas

head . group "1234" = head . (group "1234") 
                    = head . f
  where
    f = group "1234"

but group "1234" isn't a function. Remember, function application binds stronger than operators.

Upvotes: 4

Related Questions