Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Haskell evaluate expression

How come that this works

> (* 30) 4
120

but this doesn't

> * 30 40
error: parse error on input ‘*’
like image 827
Bob Ueland Avatar asked Apr 08 '26 18:04

Bob Ueland


1 Answers

(* 30) is a section, which still treats * as a binary (infix) operator, just one that's missing an argument, short for (\x -> x * 30). The parentheses themselves are part of the syntax, rather than being the explicit (but redundant) parentheses you can wrap around an arbitrary expression.

You can think of (*) as a degenerate section that is missing both arguments. You cannot otherwise use an infix operator in the prefix position without using parentheses.

like image 155
chepner Avatar answered Apr 11 '26 18:04

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!