
Copatterns in Idris - lelf
https://github.com/idris-lang/Idris-dev/wiki/Copatterns
======
sqrt17
Did someone just reinvent setf?

Honestly, I've always missed defsetf or a similar construct in languages
without macros. Python's __setitem__ and __setattr__ are already nicer than
C++'s pretense of using references, but setf gives you nice improtvement.

For non-lispers:

In common lisp, if you assign (setf) an expression, the compiler looks for the
corresponding setf-method.

As an illustration, consider

ball.roundness() = true;

where the outermost expression is a .roundness() call, which you could
transform into

ball.set_roundness(true)

without much confusion.

Note that this is conceptually more complex if you want to do this in a
purely-functional language.

~~~
eru
> Did someone just reinvent setf?

Haskellers have been at `setf' equivalents for a while now. They call them
lenses. (And add the Haskell secret sauce, to generalize setf and mapcar and
reduce etc into the same notion.)

~~~
tel
Lenses are a lot closer to setf! This copattern stuff and definition by
observation is really different.

