Earlier quoted context omitted.
Haskell has such an extensive set of language extensions, I would say adding new features to the type system is probably the MOST Haskell-ish way of doing things. The explicit purpose of Haskell is to be a basis for research into functional language design (edit: among other purposes). By "explicit purpose" I mean exactly that... people got together in 1987 to come up with a language for research. Haskell was never s…
> What are you talking about? Please edit swipes like that out of your comments here. The rest is fine and stands on its own.
Rust RAII is better than the Haskell bracket pattern
111–120 of 156 posts
Re: Rust RAII is better than the Haskell bracket pattern
#112Earlier quoted context omitted.
Is it possible? I mean, to add linear types via a library? I feel like it would have been done already if it were.
I am always impressed by what the ocaml/Haskell people can do compared to my language of choice (scheme). Iirc Oleg Kiselyov implemented proper delimited continuations in ocaml as a library, without touching the runtime or compiler. Something similar has been done in Haskell. I doubt fully dependent types can be implemented in Haskell without extra help by ghc. There has been lots of work in the area, and last time I…
To clarify this, the library you're talking about implements most of the functionality in C, reusing the runtime's exception mechanism. So it doesn't require any upstream change to compiler or runtime, but it also can't be implemented in pure OCaml.
Re: Rust RAII is better than the Haskell bracket pattern
#113Earlier quoted context omitted.
I don't know how Linux manages its memory pages. FreeBSD would put all of the anonymous pages onto essentially a free, but not zeroed queue. And there's an optional background job to zero the pages and put them in the zeroed queue. When a new page is needed, the clean queue is checked first, otherwise nonzeroed pages are zeroed on demand during allocation. (Zeroing can be theoretically skipped in cases where the kern…
Maybe a randomized sparse zeroing ?
Re: Rust RAII is better than the Haskell bracket pattern
#114Earlier quoted context omitted.
> when many C++ and Rust programs are about to end, they spend the last few cycles uselessly deallocating memory that would've immediately been freed via _exit(2) thank god they do this. how many times did I have to manually force linux to release sockets because badly coded C programs which opened sockets forgot to release them causing them to hang up for ~5 minutes after the process ended. With proper RAII classes…
Your example combined with the parents observation show that C++ put under the same construct the concepts that should be separated: memory allocation should be handled differently from the construction, destruction and other resource allocation.
Constructors are orthogonal. The job of a constructor is to construct your object given that the space for the object is already allocated. This could be on the stack, where allocation means bumping the stack pointer, or in-place in preallocated storage (like std::vector), or the result of calling `operator new`. Simply using the `new` syntax does both as a shorthand.
Similarly the job of a destructor is to destruct your object without deallocating it. One can in-place destruct without deallocating, or destruct and then deallocate implicitly when the stack pointer is adjusted, or not at all. The `delete` syntax does both destruction and deallocation as a convenience.
Re: Rust RAII is better than the Haskell bracket pattern
#115Something to keep in mind - linear types are on their way[1], with exactly this usecase in mind. Simon Peyton Jones gave an excellent presentation on the topic[2], briefly discussing exceptions, as well as giving a mention to ResourceT and the phantom type solution in the article (described as channel-passing). [1] https://arxiv.org/abs/1710.09756 [2] https://www.youtube.com/watch?v=t0mhvd3-60Y
Please, don't add them to the language. Use the library approach instead, it is much more Haskellish.
Re: Rust RAII is better than the Haskell bracket pattern
#116Earlier quoted context omitted.
Can you please dig deeper, that I am not sure I follow. In which case in rust you cannot be sure that "the drop" will be called?
If there's a cycle of strong references with Rc or Arc (or shared_ptr in C++), those objects still never get dropped/have their destructors called.
Re: Rust RAII is better than the Haskell bracket pattern
#117Earlier quoted context omitted.
Can you please dig deeper, that I am not sure I follow. In which case in rust you cannot be sure that "the drop" will be called?
If there's a cycle of strong references with Rc or Arc (or shared_ptr in C++), those objects still never get dropped/have their destructors called.
But Rc would not work if the drop was not guaranteed to be called.
Re: Rust RAII is better than the Haskell bracket pattern
#118Earlier quoted context omitted.
If there's a cycle of strong references with Rc or Arc (or shared_ptr in C++), those objects still never get dropped/have their destructors called.
Rc's drop will be called. But whether the exposed object's drop will be called is dependent on the reference count. But Rc would not work if the drop was not guaranteed to be called.
Re: Rust RAII is better than the Haskell bracket pattern
#119Earlier quoted context omitted.
The fact that this is not resolved after over a year is concerning to me. At some point you have to make a decision and implement a solution, even if not everyone agrees 100% on which solution to chose. Letting this slide for this long is a very bad sign. I’ve been a big Rust fan for my hobby projects, but the whole point of Rust is effortless correctness and safety. The more I encounter bugs and issues that have no…
> the whole point of Rust is effortless correctness and safety. Rust has never been about proving correctness. Yes, correctness is a goal, but it is subservient to other goals, depending on details. Furthermore, it's not clear that this can really be implemented in a reasonable way, see https://news.ycombinator.com/item?id=18175838 > it seems sometimes that Rust management would rather focus on cool new language enha…
Perhaps I misread this documentation; if so, I don’t think I’d be alone here. I don’t see any particular mention that dropping an fs::File could lead to data loss, and I had generally assumed major edge cases like ‘data loss from a file system library’ would be documented.
Re: Rust RAII is better than the Haskell bracket pattern
#120Earlier quoted context omitted.
> the whole point of Rust is effortless correctness and safety. Rust has never been about proving correctness. Yes, correctness is a goal, but it is subservient to other goals, depending on details. Furthermore, it's not clear that this can really be implemented in a reasonable way, see https://news.ycombinator.com/item?id=18175838 > it seems sometimes that Rust management would rather focus on cool new language enha…
Apologies if it sounded like I demanded a “cool new language enhancement” solution to this issue. On the contrary; if it were just documented that either fs::File [1] or the io::Write trait [2] could silently lose data with no error codes when dropped, that would be one such sufficient solution. Perhaps I misread this documentation; if so, I don’t think I’d be alone here. I don’t see any particular mention that dropp…