Application of arguments to function composition in Haskell -


being newbie haskell can’t understand why expression head . words “one 2 3 four” throws exception , function composition head . words must applied $ operator - expression on right of doesn’t need further evaluation because it’s single string. other way compile put head . words in parentheses (head . words) :: string -> string has same type head . words :: string -> string why putting in parentheses makes expression compile?

because of precedence rules. application has highest precedence; $ - lowest.

head . words “one 2 3 four” parsed head . (words “one 2 3 four”) i.e. words applied on string must produce function (as demanded (.)). that's not type words has:

prelude> :t words words :: string -> [string] 

head . words $ “one 2 3 four” on other hand, parsed (head . words) “one 2 3 four” , types fit.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -