Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

functional composition in haskell

How come I can't do

fst . fst (("Bob",12),10)

in Haskell?

:t fst . fst
Prelude> ((c,b),b1) -> c

Doesn't this make (("Bob",12),10) a good candidate for fst . fst since it's

(([Char],Integer),Integer)
like image 210
Jane Doe Avatar asked Feb 15 '23 05:02

Jane Doe


1 Answers

The highest precedence in Haskell is function application or f a. So

fst . fst ((a, b), a)

is parsed as

fst . (fst ((a, b), a))

which is obviously nonsense. You can fix this with the $ operator which is just function application with the lowest precedence, so f $ a == f a.

fst . fst $ ((a, b), a)

Or with some parens

(fst . fst) ((a, b), a)
like image 198
Daniel Gratzer Avatar answered Feb 23 '23 01:02

Daniel Gratzer