... | ... | @@ -178,6 +178,72 @@ Does TDNR bind more or less tightly than function application. That is, |
|
|
does "f x.g" mean "(f x).g" or "f (x.g)"? If TDNR is regarded as a kind of
|
|
|
extension of qualified names, it ought to be the latter.
|
|
|
|
|
|
## Alternative syntax
|
|
|
|
|
|
|
|
|
Another possibility for syntax is this:
|
|
|
|
|
|
```wiki
|
|
|
expr ::= atom
|
|
|
| expr atom -- Application
|
|
|
| expr dot_occ -- TDNR invocation
|
|
|
| ...
|
|
|
|
|
|
atom ::= var -- Unchanged
|
|
|
| '(' expr ')'
|
|
|
| ...
|
|
|
|
|
|
-- dot_occ is a lexeme of form ".v"
|
|
|
```
|
|
|
|
|
|
|
|
|
Here the form ".v" is a lexical token. The two forms `(f x)` and `(x .f)` are application and TDNR invocation respectively. Both forms associate to the left, so `x .f 3 .g 7 5` means `(((((x .f) 3) .g ) 7) 5)`. This means that you can stack up successive TDNR invocations without parens:
|
|
|
|
|
|
```wiki
|
|
|
m .lookup key
|
|
|
.snd
|
|
|
.reverse
|
|
|
```
|
|
|
|
|
|
|
|
|
which means `reverse(snd (lookup m key))`. And that in turn means the same as
|
|
|
|
|
|
```wiki
|
|
|
reverse . snd . (\m -> lookup m key) $ m
|
|
|
```
|
|
|
|
|
|
|
|
|
There is something odd about this, however. We'd really like to write
|
|
|
|
|
|
```wiki
|
|
|
x .reverse
|
|
|
.filter isEven
|
|
|
.map double
|
|
|
```
|
|
|
|
|
|
|
|
|
but that doesn't work because the list is `filter`'s *last* argument, not its first. Maybe you should be able to write
|
|
|
|
|
|
```wiki
|
|
|
x .reverse .(filter isEven) .(map double)
|
|
|
```
|
|
|
|
|
|
|
|
|
(Of course the spaces can be omitted). And that would be fine provided we allowed this:
|
|
|
|
|
|
```wiki
|
|
|
expr ::= atom | expr atom
|
|
|
| expr dot_occ
|
|
|
| expr '.(' var expr1 .. exprn ')
|
|
|
...
|
|
|
```
|
|
|
|
|
|
|
|
|
where `f .(g x)` means `(g x f)`. The oddness here is that the TDNR invocation can "look inside" the `.(..)` to see the function at the head. (And it had better BE a function, too.)
|
|
|
|
|
|
|
|
|
I think this is probably worth it, although it's a little odd.
|
|
|
|
|
|
## Discussion
|
|
|
|
|
|
### Works with any function
|
... | ... | |