Nilesh Trivedi

12/29/2022, 12:59 PM
It seems to me that the whole construct of functions as primitives that take arguments and produce results leads to boilerplate and duplication because it needlessly privileges arguments as "independent variables". I'll use an example to elucidate: Take a rectangle of base
and height
. It's common to think of these as "independent" variables and define quantities like the following as "dependent": •
perimeter(b, h) => 2*(b+h)
area(b, h) => b*h
diagonal(b, h) => sqrt(b^2+h^2)
But if I were to ask, what are the base and height of a rectangle whose area is
and diagonal is
, our programming languages have no tooling to do this (except the symbolic manipulation libraries for computer algebra). All the required information is there but we have privileged
and thus, we now need to figure out the formula for side lengths and program it as the function
sides(a, d)
I should be able to describe a structure, and auto-generate all possibilities functions (including for currying and partial applications, and while we are at it, all the partial derivatives with respect to each other) so that i can just declare what is known and what I want to calculate. A rectangle can then be represented with any set of variables that make everything else determinable. I should get access to all possible constructors like
new Rectangle(area: a, diagonal: d)
. And I want to see this be available for all programming tasks, not just algebra/math. For creating a graph, is the constructor
new Graph(Node[], Edges[])
really the privileged one? Why not build languages in a way that I automatically get
new Graph(AdjacencyMatrix)

Leonard Pauli

12/29/2022, 1:19 PM
Yes! Another example:
range{start.inclusive, end.exclusive, domain is int{0..30}, end=start+length, midpoint?, length?}
; By using constraints to define relations, and invertable/full on algebraic operations; an expression could be automatically reworked to isolate different set of variables; and provide ability to change them. Eg, here, changing the length will lead to an ambiguous case (>1 free variable), but with a structural editor, it may show all possible interpretations for you to select (eg. keep end or start fixed, or scale track around certain point, or add custom interpretation logic (eg. using non-linear scaling)). Integrating this system deeply with the UI would allow pretty much auto-generation of it just from the expression/range concept, auto supporting all interaction (drag track, endpoints, scale around scalepoint, etc), which would otherwise have been pages of code in eg. current web development...
(Instead of generating function... why not just keep everything declarative at its core? :)) )


12/29/2022, 2:19 PM
See, also, PROLOG, miniKanren, constraints, unification. My quickie tutorial

includes converting a query result to JSON.

Jimmy Miller

12/29/2022, 3:19 PM
You might enjoy But I’ll also just mention term rewriting in case you aren’t familiar. It’s how Mathematica is able to do the sorts of things you listed. It’s a shame there is no mainstream, non-proprietary language based on it.

Denny Vrandečić

12/29/2022, 4:44 PM
seems to me exactly what oo systems do, having different constructors, and providing methods on the objects?

Andrew F

12/29/2022, 6:03 PM
An OO system won't just casually reconstruct a side of a rectangle from the other side and the diagonal, no. TBH I'm leery of that sort of thing from a performance standpoint. I don't want to have to think too hard to know when my code is doing sqrt's. Logic programming is cool, but I definitely don't want it all the time.


12/29/2022, 7:27 PM
aside: If you need to steal/get-ideas-from code: the yawningly easiest-to-understand implementation of PROLOG is Nils Holm’s (it’s so easy, that I ported it to 2 other languages - JavaScript and CL). If you want to dig in and make an optimized PROLOG, look at WAM (Warren Abstract Machine). Ait Kaci’s tutorial is helpful (I had found a $0 download, but can’t find it at this moment). Gprolog is implemented with WAM and can be forced to show what WAM it generates. MiniKanren is relational programming done without backtracking

Konrad Hinsen

12/29/2022, 7:31 PM
This issue is quite serious in scientific computing. A mathematical equation is a lot more than a piece of code that implements a particular evaluation based on it. And yet, we see equations disappear, to be replaced by less valuable code. My attempt to fix this is to move from programming to specification languages. You'd write equations defining the relations for a rectangle in the specification languages, and then either read them into your program, or derive your program from them. Details:


01/01/2023, 4:49 AM
Relatedly, most if not all validation concerns arise from data dependencies. Take, for instance, an
with a
and an
. Naturally, we should have
start_date ≤ end_date
in the end, but for a UI, it can be nice to choose them in either order or to have an
that then gets fixed by the time you use it. But some operations over regular events still sense for inconsistent events. Now I
Also thinking about scheduling dependencies from assembling LEGO with my son and his friend yesterday. Friend's mind was blown to see son and I concurrently working on different steps. Earlier this year, concurrency concerns lead me down a path to radically improving the expressivity of my software's model layer because being explicit about data-dependencies allowed for context-based resolution of references.

Tom Hutchinson

01/03/2023, 5:13 AM
Something similar to this approach is Clojure
You write your code in the form of “resolvers” which establish relationships between attributes, then you simply give it some input data (in the form of an immutable map) and make a query (in the form of EQL) and the Pathom system determines the resolvers that need to run in order to fulfil your query.
This video by the creator is good but a bit more focused on using it to combine APIs


Nilesh Trivedi

01/03/2023, 10:57 AM
@Tom Hutchinson This was really interesting and highly relevant. Thanks for sharing!

Riley Stewart

01/19/2023, 1:24 AM
There's also something like this in Modelica