Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm surprised no-one has mentioned Haskell's ST library yet. It hits this exact use-case, and comes with some pretty sweet safeguards from the type system.

https://wiki.haskell.org/Monad/ST

It allows you mutate arrays and other stuff "on the inside" like this article suggests, but it's also able to wrap up the operation so it appears pure from the outside, so the caller doesn't have to guess or rely on naming conventions to figure out the mutability.

It's your choice on whether you want to do the copy on the way in ('thawing'), on the way out ('freezing'), or both, by using the 'in-place' variants of thaw and freeze.



Exactly. The only problem is that you need a language with a sufficiently powerful type system that can express both phantom and existential types.


> The only problem is that you need a language with a sufficiently powerful type system

why is that a problem?


Because everyone and their grandma can whip up a quick Python script after a few days of practice, whereas learning Haskell is a much bigger investment?


Problem in the sense that most typed languages don't have a sufficiently powerful/expressive type system.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: