31 ms·
Hurl, the Exceptional Language
- kibwen 2y ago> Now let's see an example with toss. This is used mostly for passing multiple values out of the function. You don't really need it, but it's cute. Not useful? You've implemented resumable generators! Of course, getting them to do anything except resume immediately might be... exciting. :P Just need to structure your entire codebase as an inside-out stack of `toss`es...
- adastra22 2y agoYeah that made me chuckle. I wish the languages I use had resumable exception handling. This is a ridiculously good, and extremely useful feature. Great for API callbacks, among other things.
- grumpyprole 2y agoOCaml 5 essentially has it, as "effect handlers". It's how lightweight concurrency is implementated.
- 1propionyl 2y agoExactly my first thought after reading that. Part of me wonders if it's a bit of a joke, panning a genuinely useful feature (in any other language) as disposable and silly (in this one).
- DeathArrow 2y ago>You've implemented resumable generators! Like yield in C#?
- kleiba 2y agoRight. Lots of fun ahead debugging a larger codebase :-)
- int_19h 2y agoNot quite, since with resumable generators you can resume at any later point in the program, while here "return" must be lexically scoped to the handler (whereas in e.g. Python you can call next() wherever). This is really more like passing a callback through a side channel. "toss" is invoking said callback, and "return" is, well, returning from it.
- boromisp 2y agoIt's more like stack based event propagation.
- Vivtek 2y agoThat was my first thought, too. Nice, tiny language with generators? Neat!
- hgyjnbdet 2y agoNaming conflict with Hurl[0] a command line tool that runs HTTP requests defined in a simple plain text format. [0] https://hurl.dev/docs/manual.html https://hurl.dev/docs/manual.html
- tgv 2y agoMultiple products sharing a name is unavoidable. Github had 90,000 unique repositories in its first year. If each had to have a unique name, it would almost have exhausted the English dictionary. In 2018, it reached 100 million repositories.
- thegeekpirate 2y agoEveryone understands that, but when the project name you're copying is popular enough (12k stars meets this threshold, personally) and is still actively used and developed, a name change should be more seriously considered as to avoid confusion (which I exhibited, fwiw).
- polytely 2y agoWell it's a totally different category of thing (in multiple ways) so I can't imagine people getting confused about this.
- falcor84 2y agoI have a proposal: let's accept as a given that all single words have been taken, and require all new languages/tools to be named with either multiple words, or by including a special character. Note that C# (aka C Sharp) was way ahead of its time by including both options.
- lylejantzi3rd 2y agoIf I ever create a language, I'm calling it clang for maximum naming conflict. Am I talking about the c language? The compiler? or this newfangled language written by a completely unqualified web dev? ¯\_(ツ)_/¯
- helix278 2y agoThis sounds like a weaker form of algebraic effects, but it is still cool to see such a language and see what you can do with it.
- levzettelin 2y agoI never understood "algebraic effects". But I understand the Hurl docs. Are "algebraic effects" basically the "toss" keyword from Hurl? If so, how are "algebraic effects" stronger than the "toss" keyword?
- ctenb 2y agoMore general than the toss keyword even. If you're interested in concrete examples, you might have a look at the koka documentation
- throw156754228 2y agoAs mentioned in another comment here, the unwind is expensive. That is, searching back through the stack finding the original call site that triggered the exception. How do algebraic effects handle that performance hit?
- fwip 2y agoYou can think of algebraic effects kind of like: From callsite Foo, I call out to a function with a known name, Bar, with one or more parameters. The runtime (or sufficiently smart compiler) searches upwards in scope, for a handler Baz that provides the function with that name. Baz's Bar is then called, with both the provided parameters, and, crucially, a function that is "the rest of Foo." So, an implementation of Exception with effects would ignore the resume, and look something like: define_effect Exception { // only one function provided by Exception, but could have more throw(String) } define_handler printExceptions { throw(msg, resume_func): { println(msg) } } define_func getPage(url) { request = http.get(url) if not request.ok { throw("Could not download") } return page } // main entrypoint withHandlers printExceptions { page = getPage("https://cheese.com") println(page.text) } But you could also write an "on error resume next" handler for Exception. Exceptions thrown with this handler would be equivalent to toss. (in real life you'd probably write a different effect, rather than re-using the Exception/throw effect): define_handler onErrorResumeNext { throw(msg, resume_func): { println(msg) // YOLO, call it anyways withHandlers onErrorResumeNext { resume_func() } } } withHandlers onErrorResumeNext { page = getPage("https://cheese.com") println(page.text) // Probably uninitialized - a better :P } Breaking away from the Exception example, two cool examples are: // Stream - potentially infinite and/or asynchronous iterables // basically just like python generators define_effect Stream { emit(item) } define_handler toList(accumulator) { emit(item, resume_func): { if item == nil { return accumulator } else { accumulator.append(item) withHandlers toList { resume_func() } } } } define_handler take(how_many) { emit(item, resume_func) { if how_many == 0 { emit nil } else { withHandlers take(how_many-1) { resume_func() } } } } define_func fib_stream() { a, b = 0, 1 loop { emit a a, b = b, a+b } } // Usage first_five = withHandlers toList { withHandlers take(5) { fib() } } println("The first five fibonacci numbers are", first_five) And this one I'm just going to lift from the Unison documentation [1]: Each.toList do a = Each.range 0 5 -- beginning of resume_func f_A b = each [1, 2, 3] -- beginning of resume_func f_B guard (a < b) -- beginning of resume_func f_C (a, b) -- yields [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] Note that this has the same semantics as: results = [] for (a = 0; a < 5 ; a++) { // for each a, call f_A(a) foreach b in [1, 2, 3] { // for each b, call f_B(b) if not a<b { continue } // if a<b, call f_C(a, b) results.append((a, b)) } } And it is possible to do this, because these resumable functions can be resumed an arbitrary number of times - it's up to the handler. They also can pass parameters back to the resume_func. Exceptions/hurl = exactly 0 resumptions toss = exactly 1 resumption effects = 0..many resumptions [1]: https://share.unison-lang.org/@unison/base/code/releases/3.5.0/latest/types/abilities/Each https://share.unison-lang.org/@unison/base/code/releases/3.5...
- masklinn 2y agoHurl seems very close to having a conditions system (à la Smalltalk / CL): unwinding and resuming are just two possible restarts (https://gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts#providing-multiple-restarts https://gigamonkeys.com/book/beyond-exception-handling-condi...).
- kgeist 2y ago'Toss' sounds like an interesting language construct: it walks the stack to find an exception handler and then walks back to where it was to resume execution as if nothing happened. It looks like you can inject additional behavior at runtime using this construct. Usually in object-oriented code you do dependency injection using services's constructors, but 'toss' allows to do it using "toss handlers"?
- bradrn 2y agoThis is quite similar to the Common Lisp conditions system… which I actually don’t know much about, but I do know that it lets you inject behaviour at runtime like this does.
- masklinn 2y agoIt's a very restricted form of conditions, since it only allows resuming. A conditions system would subsume both `toss` and `hurl` (because you can have an unwinding restart), as well as provide more flexibility: the condition can provide multiple user-defined restarts and the handler can pick between them (statically or dynamically), as well as feed content back into the signalling function. For instance a classic CL restart is `use-value` which is the conventional name of restarts feeding a default value in case of missing or invalid item. So let's say that you have a hashmap type, on lookup failure it could trigger a condition with a `use-value` handler to feed it a default value (possibly dynamically constructed), or abort/unwind, it could also have a restart to insert-and-return the value (so would behave as a `defaultdict`/`putIfAbsent`)
- mjbrusso 2y agoThis is similar `Resume Next` in VB
- tylerhou 2y agoCheck out Koka, a “legit” language with an algebraic effect system. https://koka-lang.github.io/koka/doc/book.html#why-handlers https://koka-lang.github.io/koka/doc/book.html#why-handlers
- z3t4 2y agoFor anyone designing a programming language, enforce namespace to includes/imports! and if possible, don't allow top level side effects. let foo = include "lib/foo.hurl" foo.init() it's much easier to reason about then, for example: include "lib/foo.hurl" // side effects baz(buz) // function and variable that I have no idea if they are in the standard library, or included *somewhere* That way it's much easier
- moomin 2y agoI mean, it’s a language based around exceptions for flow control, I think the “easy to reason about” ship has sailed. (Don’t confuse this with me thinking this project is worthless, I think it’s art.)
- infogulch 2y agoI agree, side-effecting imports add to the spooky action at a distance aesthetic.
- karma_pharmer 2y agoi think you mean to to say "has sunk"
- groestl 2y ago> I mean, it’s a language based around exceptions for flow control, I think the “easy to reason about” ship has sailed. Sometimes I wonder if I'm exceptionally (haha) talented as I personally find the impact of exceptions on flow control pretty easy to grasp. But based on my understanding of other advanced computer language concepts, which is pretty lacking in some regards, I come to the conclusion that it can't be too hard, and people make a lot of fuss about it for no particular reason.
- eyelidlessness 2y agoIt’s largely difficult because either: - you’re working in a language that doesn’t have checked exceptions, so the set of potential errors and the set of potentially error-raising calls is infinite but unknowable - you’re working in a language that has checked exceptions, and you hate that it makes you do work, so you catch-rethrow runtime errors that recreate the first scenario - you’re working in a language that has checked exceptions, but someone else did the second scenario so you’re in the first scenario anyway
- Aeolun 2y agoNot related to the project as such, but I am firmly of the opinion that the world would be a better place if more things used the .wtf extension for their domain :)
- MidhaelBollox 2y agoYou have reached the maximum number of changes allowed. Please subscribe to make more changes.
- zeroCalories 2y agoI've always kinda hated exceptions as it makes the contract between a caller and a callee hard to determine, and makes your code highly coupled. I prefer the Go or Rust style of handling it through return values. Briefly skimming the language, I'm not sure if there is anything that fixes that? I think this kind of model could be cool if your IDE could dynamically determine all uncaught exceptions for a function, and lets you jump to each possible place where the exception could be thrown. Not sure how you handle coupling though. This seems like it would result in an insanely volatile control flow graph.
- mbmjertan 2y agoThis is what IntelliJ does for Java. A problem is reported whenever you have a function that throws exceptions and isn’t caught in a caller anywhere in the project, and you can jump to implementation or calls easily. However, exceptions that a function can throw are part of the function signature in Java unless they extend RuntimeException (and in that case your program won’t compile if you throw an exception without adding it to the signature). While the circumstances in Java make it much easier for IDEs to report uncaught exceptions, it’s a solvable problem for non-runtime exceptions using static analysis. On the other hand, returning standardised Ok/Err-wrapped values seems like a simpler approach, both in terms of tooling support and developer convenience.
- DarkNova6 2y agoI think once Java has finished up exception switch-case it will be a model followed by other languages. Being able to catch exceptions at both, method and transaction boundaries will be a boon for readable control-flow.
- throw156754228 2y agoAlgebraic effects is going in completely the opposite direction.
- mrkeen 2y ago> and transaction boundaries What are transaction boundaries? Is Java getting transactions?
- ceving 2y agoIs it implemented using CPS conversion?
- baq 2y agoIt certainly looks like continuation passing everywhere manually.
- junon 2y agoGay Agenda License 1.0 had me laughing.
- emersion 2y agohttps://git.sr.ht/~ntietz/hurl-lang/tree/main/item/LICENSE/GAL-1.0 https://git.sr.ht/~ntietz/hurl-lang/tree/main/item/LICENSE/G...
- NoahKAndrews 2y agoThis is fantastic
- andrewshadura 2y agoUnfortunately, it's not open source, but it's still hilarious :)
- zzo38computer 2y agoAlthough it is not open source, this program can also be used with AGPL3 which is a open source license, so it is good enough.
- DaveFlater 2y agoSee: https://news.ycombinator.com/item?id=36393673 https://news.ycombinator.com/item?id=36393673
- tombert 2y agoJust rebrand this as “algebraic effects” and suddenly every academic will pretend it’s revolutionary.
- deleted 2y ago[deleted]
- withoutboats3 2y agoAlso my thought. It's very interesting how the designers of this language, presumably unaware of algebraic effects, write about it as if it a terrible joke when this is actually one of the trendiest ideas in PL.
- cushpush 2y agoDon't just throw it, hurl it
- zbentley 2y agoWow, I hate this. But it’s … oddly almost kinda elegant? In a very hard to mentally model way, but even so. Speaking more seriously than is perhaps warranted, I’d slightly prefer it if there were syntactically different “catch” constructs for resumable and nonresumable exceptions, which would remove syntactic ambiguity around whether “return” was sending control flow back to the thrower of the nearest immediate exception or not. Also, the stdlib shouldn’t have chickened out with regular value-returning functions. Just because the dogfood gives you heartburn doesn’t mean you shouldn’t eat it :)
- zzo38computer 2y ago> Also, the stdlib shouldn’t have chickened out with regular value-returning functions. Just because the dogfood gives you heartburn doesn’t mean you shouldn’t eat it :) Yes, although an alternative would be to make the syntax if you call the function where a value is expected, then it will automatically catch.
- zzo38computer 2y agoAnother alternative would be to use macros instead.
- jokethrowaway 2y agoNice thought experiment. I absolutely hate exceptions and I'd like a language without exception. They're the goto of our time. When we have Maybe/Option and Effect/Result, there is really no reason to throw exceptions and having to mentally track where that is being handled. I'm a bit worried about algebraic effects becoming more popular (and influencing frontend JS - which is already way too complex) because it's promoting throwing "exceptions" to control the flow. All of this to avoid the coloring problem in async/sync? Absolutely not worth it imho.
- tempodox 2y agoDid I get that right that you can catch what was hurled but not what was tossed? That will take some getting used to. Also, I am concerned about how much Hurl I can write before people start calling me a tosser?
- brundolf 2y agoTop-tier wordplay
- frithsun 2y agoShame that you guys don't actually believe in this, as it's actually the way.
- Alifatisk 2y agoI knew I recognized that name, it’s from hurl.dev