[HN Gopher] Algebraic data types in Lua (almost)
___________________________________________________________________
Algebraic data types in Lua (almost)
Author : mrcjkb
Score : 53 points
Date : 2023-08-17 16:01 UTC (1 days ago)
(HTM) web link (mrcjkb.dev)
(TXT) w3m dump (mrcjkb.dev)
| gsuuon wrote:
| I think the main concept introduced here is to hand-write what
| would be the match expression for each union. I've done similar
| stuff in languages with no ADT's, but without exhaustiveness
| checking you're left with co-locating the matcher next to the
| union type and hoping you remember to update it if anything
| changes.
| shadowgovt wrote:
| Pretty fascinating stuff. I wasn't aware of the push to do some
| static annotations in Lua and that seems like a great idea.
|
| I've used at least three bespoke configuration languages where I
| eventually had to ask "Why isn't this just Lua?" I highly
| recommend embedding Lua as the first option over writing one's
| own config language and parser any time someone suggests it.
| conaclos wrote:
| I wonder why the author doesn't use Teal [0] - a typed dialect
| of lua.
|
| [O] https://github.com/teal-language/tl
| connicpu wrote:
| Absolutely. I built my own DIY thermostat and was spending
| weeks of free time working on the configuration system for it
| so that it could do the things I wanted. I thought I had a
| decent system for it, and then I realized it's a pain in the
| ass to work with in its JSON format. Rather than find a
| language that would make the configuration model easier to work
| with or building an entire UI for it, I finally realized it
| would be way easier to just do it as code, and there was no
| better choice than Lua.
|
| Add a few helper functions, and the configuration that
| dynamically changes the target temps throughout the day is a 12
| line Lua function that determines what the HVAC system should
| do based on the current state, current time, and the current
| temperature.
| shadowgovt wrote:
| The biggest criticism I've heard is "I don't want my config
| language to be Turing-complete."
|
| I agree; nobody does. But two of the three config languages I
| used started out as static no-frills languages and eventually
| _became_ Turing-complete by accretion of need to support more
| and more complicated configurations, and given that they were
| headed there eventually, I wish they 'd been Lua instead of a
| Turing-complete bespoke language with its own parser, its own
| (bad) error messages, little thought paid to debugging ("hey,
| it was never supposed to be complicated enough to need
| debugging!"), and no tooling.
___________________________________________________________________
(page generated 2023-08-18 23:01 UTC)