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
Post a Comment