1,199 karma · joined September 10, 2015
In short a combinator is a pure function that accesses only identifiers that are provided as arguments.
Length(x,y) { sqrt(xx + yy) } is not a combinator because it relies on global definitions for plus, times and sqrt.
But foo(x, y, b, u, v) { v(b(u(x), u(y))) } is a combinator because it only composes functions that are given as arguments.
Foo(3,5,+,square,sqrt) would result in the same value as length(3,5) so foo can be regarded as capturing the compositional structure of the euclidean distance calculation.
3Blue1Brown just released an amazing video explaining the geometric transformation for Eschers print gallery. This made me try to reimplement the effect as WebGL shader [1].
It was very much fun especially doing it fully on my own just based on the general idea without looking at actual existing implementations. It highlighted for me how in non-linear transformations even small mistakes on my side can have huge negative effects on the final image that are tricky to pin down due to the non-linearity.
With subgrid the rows and columns of two sibling grids are aligned with each other by glueing them to the rows and columns of the parent grid.
[1]: https://youtu.be/ef2jpjTEB5U?si=S7sYRIDJKbdiwYml
[2]: https://youtube.com/playlist?list=PLfGbKGqfmpEJofmpKra57N0FT...
Lenses are an embedded dsl for doing this via syntax that reads similar to to the mutable variant. Additionally it allows to compose many of such transformations.
You can think of it as an functional programming based embedded domain specific language for transforming immutable data structures into each other. Sure there are other ways to do it but its like generalized map/filter/reduce class of functions vs doing the same imperatively by hand or in other ways
In the end it is really just function composition but in a very concise and powerful way.
In your cambria example the lens is defined as yaml. So this yaml needs to be parsed and interpreted and the applied to the target data. The rules that are allowed to be used in the yaml format must be defined somewhere. With pure functional lenses the same kind of transformation rules can be defined just by function composition of similar elemental rules that are itself only pairs of functions.
This is very detailed introduction and documetation of a lense-based architecture in react. [2] At the first glance it looks kind of overwhelming but it contains lots of examples.
This is a case study of many rather complex components. [3] The codinsteade is rather quick and dirty hacked together and at the first glance not really readable but thats kind of the point: even complex components can simply be composed locally from many small parts of requiring some global controller managing the state and keeping it consistent.
1: https://svelte.dev/playground/ea842faa235540bba43d7970ecf8ce...
2: https://github.com/calmm-js/documentation/blob/master/introd...
But the main benefit is not only the persistence of the app state, but composable globally consistent state. With most state management solutions at some point you hit a wall where communicating state changes between far away components is really difficult. You need to manually manage eventlistener lifecycles, route events through the application and convert events into state changes and state changes into events, while not causing cycles or unstable feedback loops or race conditions.
With lenses the state tree is composed declaratively and locally. each component does not need to care if the parent state is locally constructed or coming from further away.
/edit: Actually using this approach you are not forced to have a single global state but instead each component can simply decide to embed its child components state into its own state or not. If all components decide to embed their children state you get a single global state. But if all components decide to not embed their children state you get only local state with no communication. But the unified Interface gives you the choice.
In every language there are sharp edges or dirty corners that are just annoying once you hit them. JavaScript and Php are full of inconsistencies, Ruby and Python are nice and the surface but once you dive into meta programming, OOP and mutability complex code bases are just impossible to trust/reason about their correctness. Rust, C++, C#, F#, Java... I could go on.
In my opinion Elixir just hits the sweet spot of good design. After multiple years using it there comes nothing to my mind that I find ugly or annoying.
Sure there are other languages that are quiet nice on paper but often they lack the ecosystem to let you just build production ready stuff. The Elixir ecosystem is also not that large, but large enough for quickly building a web app or composing useful automation pipelines.
Yes the simplest way to think of it is to exponentiate the dft matrix to an exponent between 0 and 1 (1 being the classic dft). But then the runtime complexity is O(n^2) (vector multiplied with precomputed matrix) or O(n^3) opposed to the O(n log n) of fast fourier transform. There are tricks to do a fast fractional fourier transform by multiplying and convolving with a chirp signal. My implementation is in rust [1] compiled to web assembly, but it is based on the matlab of [2] who gladly answered all my mails asking many questions despite already being retired.
[1]: https://github.com/laszlokorte/svelte-rust-fft/tree/master/s...
(Fractional fourier transform on the top face of the cube)
And for short time fourier transform showing how a filter kernel is shiftes across the signal. [2]
I later optimized the hotpath and it is significantly faster (still miles behind webgl/webgpu obviously). You can try yourself if you scroll alll the way to the veeeerrrry bottom here [3].
[1]: https://github.com/calmm-js/partial.lenses [2]: https://ramdajs.com/ [3]: https://static.laszlokorte.de/svatom/
If I had to guess:
fun flip_all([Posn(x, y), rest]):
[Posn(y, x), rest]
If I am correct then the only difference between flipping all and flipping just the first is `...` vs `rest`