disco-lang / disco

Functional teaching language for use in a discrete mathematics course
Other
158 stars 22 forks source link

Built-in function composition operator #254

Open byorgey opened 3 years ago

byorgey commented 3 years ago

Eventually, once #136 is addressed, function composition can simply be in a library. However, for now it might be nice to have function composition as a built-in operator.

Note this does create a bit of an issue with disambiguating multiplication and function application. Currently, any application of a binary operator is seen as a "multiplicative term" when it occurs as the left-hand argument to a juxtaposition. That is currently justified since no binary operator can have a function as output. But of course that would not be true anymore if we add a function composition operator. Options include (1) adding an explicit function application operator, (2) subdividing binary operators into two sets, those which can output a function and those which can't, and deciding on multiplication vs application based on that.

byorgey commented 2 years ago

Note #84 would have a similar issue: now binary operators like + could output a function as well. In that case obviously we could not use option (2), of having two distinct sets of operators that can and can't return a function, since + could do both.