Live data from Hacker News

The Hare programming language

harelang.org

61–70 of 323 posts

Re: The Hare programming language

#61

Earlier quoted context omitted.

I can sort of understand where you're coming from — manual memory management can be difficult, and doing it improperly can cause bugs. However, in my experience, we're very far from having a magical solution for memory management. C++ definitely isn't it, and while Rust does bring significant advances in this field, it's a very large and complicated language. Unfortunately, the memory management strategy of every oth…

> C++ definitely isn't it, and while Rust does bring significant advances in this field, it's a very large and complicated language. It really isn't. Not compared to C++, at least. Or to managed language runtimes, which are just as "large and complicated", only beneath the hood.

Putting things "below the hood" with as few leaks as possible is one of the key ways of managing complexity. So if a language can do this for a certain set of use cases then it's worth using for those use cases. Everything becomes quicker and more productive. There's a reason people that few people nowadays write the server side of web applications in C++. Rust isn't a huge improvement for that use case compared to a managed language.

Re: The Hare programming language

#62
post #46

Earlier quoted context omitted.

The biggest missing feature here would be a way to not only select by type and for example allow something like type foo = (A int | B int) Which from my cursory reading does not seem to be possible?

I'm not sure what you mean by "select by type". I can say that you can define new types: type a = int; type b = int; type c = (a | b); Which seems to be what you're angling for here? I also suspect that you're approaching this from a Rust- or Zig-like background where enums and tagged unions are closely related; this is not so in Hare.

I do know those languages, but this is more the ADT way from ML.

The example you linked did not really make it clear from my point of view because one of the points is that it will collapse if there are multiples of a specific type. But your way seems to make it possible.

Re: The Hare programming language

#63

Earlier quoted context omitted.

Not staticassertion, but I'm a hobbyist in real-time audio. I like Rust as a vocabulary for describing/teaching safe programming (&/&mut/Send/Sync). I find that multithreaded programs written in Rust are usually correct while multithreaded programs written in C++ are usually wrong, because Rust encodes the rules of shared-memory threading in its type system (&T: Sync objects are thread-shared, but are either immutabl…

> However I find it makes it too difficult to mutate through shared references It's not that difficult, you just need to use UnsafeCell or one of its safe derivatives (each of which has some potential runtime overhead) to keep the semantics tractable.

One of the strange things about Rust is the &UnsafeCell/*mut T dichotomy. &UnsafeCell is easier to work with, and you can soundly acquire &mut T as long as they never overlap, but you can't turn a Box> into a &UnsafeCell and back to a Box> to delete it, because provenance or something.

*mut T is harder to work with, this is UB according to miri since you didn't specify `&mut x as *mut i32 as *const i32`:

    let mut x = 1;
    let px = &mut x as *const i32;
    unsafe {
        *(px as *mut i32) = 2;
    }
Problem is, most APIs won't give you a &UnsafeCell but rather a &mut T. Not sure if you can convert a &mut T to a &UnsafeCell (you definitely can't using `as`). If you want to create multiple aliasing pointers into a non-UnsafeCell type or struct field, one approach (basically a placeholder since &raw isn't stable, https://gankra.github.io/blah/fix-rust-pointers/#offsets-and...) is:

    let mut x = 1;
    let px = addr_of_mut!(x);
    unsafe {
        *px = 2;
    }

Re: The Hare programming language

#64

lol my other post got flagged, so let me reiterate perhaps in a less inflammatory way. It is disappointing to see that "trust the programmer" is a design goal. Programmers can not be trusted with manual memory management. We have decades of proof, billions and billions of dollars of bug fixes and mitigation investments, real world damages, etc. Building a language like this and saying you hope it will be the foundati…

No post body was provided.

Re: The Hare programming language

#65
post #62

Earlier quoted context omitted.

I'm not sure what you mean by "select by type". I can say that you can define new types: type a = int; type b = int; type c = (a | b); Which seems to be what you're angling for here? I also suspect that you're approaching this from a Rust- or Zig-like background where enums and tagged unions are closely related; this is not so in Hare.

I do know those languages, but this is more the ADT way from ML. The example you linked did not really make it clear from my point of view because one of the points is that it will collapse if there are multiples of a specific type. But your way seems to make it possible.

Right - but defining a type alias makes a new type, which does not collapse.

Re: The Hare programming language

#66

lol my other post got flagged, so let me reiterate perhaps in a less inflammatory way. It is disappointing to see that "trust the programmer" is a design goal. Programmers can not be trusted with manual memory management. We have decades of proof, billions and billions of dollars of bug fixes and mitigation investments, real world damages, etc. Building a language like this and saying you hope it will be the foundati…

Quoted post unavailable.

While Drew is the designer of Hare, a lot of us worked on Hare, and we tried really hard to create something useful and valuable. I think it would be a shame if you disregard it because of something that Drew said at whatever point in time. If you have the time, please try Hare and let us know what you think!

Aside from that, the question of memory safety is more complex than you make it out to be, and Drew, myself and others have discussed it in a lot of detail in this thread, Drew mentioned there are many memory safety features, potential plans for an optional borrow checker and so on — please draw your conclusions based on the full information.

Re: The Hare programming language

#67

lol my other post got flagged, so let me reiterate perhaps in a less inflammatory way. It is disappointing to see that "trust the programmer" is a design goal. Programmers can not be trusted with manual memory management. We have decades of proof, billions and billions of dollars of bug fixes and mitigation investments, real world damages, etc. Building a language like this and saying you hope it will be the foundati…

Quoted post unavailable.

Is appreciating Rust some kind of high ideal in the world of programming?

Re: The Hare programming language

#68

lol my other post got flagged, so let me reiterate perhaps in a less inflammatory way. It is disappointing to see that "trust the programmer" is a design goal. Programmers can not be trusted with manual memory management. We have decades of proof, billions and billions of dollars of bug fixes and mitigation investments, real world damages, etc. Building a language like this and saying you hope it will be the foundati…

Quoted post unavailable.

This is a very unsympathetic take. If you expand to the full context, you'll note that I weigh memory safety against other trade-offs, and come away with a different answer than Rust does.

Hare does have safety features. Checked array and slice access, mandatory error handling, switch/match exhaustivity, nullable pointer types, mandatory initializers, no undefined behavior, and so on. It is much safer than C. It just doesn't have a borrow checker.

Re: The Hare programming language

#69

Earlier quoted context omitted.

FWIW, frequently I've wished that languages had a version of https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html built-in for implementing iterators, like Python generators, or somewhat similar to async/await. Porting the macros to C++ suffers because switches can't jump past declaring local variables with required constructors, and my hacks around this issue were ugly and error-prone. I haven't learned C++…

We do not have first-class iterators, but we do have an iterator pattern which is common throughout the Hare standard library. As an example, here's how you can enumerate the nodes in a directory: let iter = os::iter("/")!; for (true) { const entry = match (fs::next(&iter)) { case let ent: fs::dirent => yield ent; case void => break; }; fs::println(entry.name)!; };

I understand not having first-class iterators; Rust traits encourage using option/iterator combinator methods rather than imperative code, which I find unclear in nearly all cases (though iterator reduce() is better at finding the min/max of a sequence, since you don't have to initialize the counter to a sentinel value). I was discussing the use of coroutines for building iterators, for example implementing the next function for a recursive filesystem glob or B-tree map iterator or database table join, which I find miserable and bug-prone to write by hand.

Re: The Hare programming language

#70
post #8
post #7

How does this compare to Zig? They seem to share the same problem space.

Hare is much simpler than Zig and has a much different design, things like Zig's comptime is absent in Hare. Hare also has, in my opinion, a more fleshed out standard library than Zig. However, they don't compete in some respects: Zig targets nonfree platforms like Windows and macOS, and being based on LLVM gives Zig a greater range of platforms/architectures OOTB. Andrew might be able to expand on this.

comptime is absolutely the biggest difference, in Zig you'll find high quality, performant generic hash map implementations in the standard library. In hare there are no generics and you are encouraged to write your own hash maps as needed: https://harelang.org/blog/2021-03-26-high-level-data-structu...
Post reply on HN