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)
1 Answer 1
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)
answered Jan 4, 2014 at 4:15
daniel gratzer
54k11 gold badges100 silver badges137 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Jane Doe
What's more haskell-esque - the $ operator or parentheses?
daniel gratzer
@JaneDoe
$ in generallang-hs
fst . (fst (("Bob",12),10))whereas you want(fst . fst) (("Bob",12),10).