user2879704
user2879704

Reputation:

Dot Versus Dollar symbol

print $ concat ["abc", "bde"]

prints

abcbde

whereas,

print . concat ["abc", "bde"]

The error thrown in second case is,

Couldn't match expected type ‘a -> b0’ with actual type ‘[Char]’
Relevant bindings include
  it :: a -> IO () (bound at <interactive>:3:1)
Possible cause: ‘concat’ is applied to too many arguments

. (function-composition operator) is used because i thought it will take the output of concat function and pass it to the preceding function print? What is wrong in the code?

Upvotes: 2

Views: 474

Answers (1)

Ry-
Ry-

Reputation: 224903

Just precedence, really; this will work fine:

(print . concat) ["abc", "bde"]

. composes two functions to create a new function, whereas $ is just a way of avoiding parentheses in this context.

Upvotes: 7

Related Questions