-2
mul (add 2 3) 5

Can the dot (.) and dollar ($) operators alone replace the brackets? The mul and add functions are filler, i.e. the order of application must stay the same. This is an exercise to better understand the aforementioned operators.

wizzup
  • 2,361
  • 20
  • 34
Ware
  • 97
  • 6

2 Answers2

1

You can use the combinator flip to allow you to reverse the order of the arguments. each following line is equivalent:

mul (add 2 3) 5
(flip mul) 5 (add 2 3)
flip mul 5 $ add 2 3

flip is defined as simply:

flip :: (a -> b -> c) -> (b -> a -> c)
flip f b a = f a b

However, I don't believe the two operators . and $ alone are sufficient

duplode
  • 33,731
  • 7
  • 79
  • 150
Zoey Hewll
  • 4,788
  • 2
  • 20
  • 33
0

You could use the algebraic properties of mul:

mul 5 $ add 2 3
Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166