logoalt Hacker News

daxfohlyesterday at 6:00 PM2 repliesview on HN

The only thing is I wish there was a way to safely lift a row-polymorphic record to a named record type if the compiler can determine it has all the required fields. Haven't seen any languages that offer this yet though.


Replies

continuationalyesterday at 6:10 PM

Firefly can construct any named record from any other record (named or anonymous):

    let point = (x = 5, y = 7)
    let point3d = point.Point3d(z = 0)
We included this feature specifically to make it easy to use named and unnamed records together.

More here: https://www.firefly-lang.org/

owlstuffingyesterday at 6:14 PM

The manifold project[1] for Java provides that feature as "Structural Interfaces" which supports polymorphic variants.

The project also supports tuples that behave similarly.

    var person = (name: "Joe", age: 35);
    . . .
    Person p = person; // tuple's name, age properties satisfy Person record
1. https://github.com/manifold-systems/manifold