3 ms·
> Expressive, pretty powerful, ML and Haskell inspired type system It's great that they use this, but it's still difficult to program in a purely functional st
by amelius 6y ago
> Expressive, pretty powerful, ML and Haskell inspired type system
It's great that they use this, but it's still difficult to program in a purely functional style in Rust the way you would in, say, Haskell, because of memory management. Closures can create memory dependencies which are too difficult to manage with Rust's static tools.
- ohazi 6y agoThis is definitely true, but you can often get surprisingly far by just boxing, cloning, Rc-ing, etc. whenever you hit something like this.
- amelius 6y agoYes, but doesn't the additional housekeeping negate much of the elegance of Haskell?
- acomar 6y agothe bigger issue is around the combination of closures, generic parameters, and traits. because higher-rank types can't be expressed and closures are all `impl Fn()`, you start to get an explosion in the complexity of managing the types and implementing the trait. try implementing something in the "finally tagless" style for an example of the kinds of things that can go wrong really fast. `Box` and `Rc` don't get you out of it and the resulting implementation is brittle and boiler-plate heavy in actual use. from memory: trait Prop<'a, T> { fn p<F: Fn(&'a T) -> bool>(f: F) -> Self; fn eval(&self, &'a T) -> bool; } enum LiftedBool<'a, T, F: Fn(&'a T) -> bool> { Base(Box<F>), And(LiftedBool<'a, T, F>, LiftedBool<'a, T, F>), Or(LiftedBool<'a, T, F>, LiftedBool<'a, T, F>), Not(LiftedBool<'a, T, F>), } impl<'a, T, F: Fn(&'a T) -> bool> Prop<'a, T> for LiftedBool<'a, T, F> { fn p<F: Fn(&'a T) -> bool>(f: F) -> Self { // this fails because `F` in the impl doesn't necessarily unify with `F` in the trait definition // it can be made to work with `dyn` for the function argument but requires boilerplate to actually use } fn eval(&self, &'a T) -> bool { // obvious evaluation by cases } } this example can be fixed to work via `dyn` for the argument on the trait function and the struct itself but it becomes increasingly painful to actually work with. this kind of generic work is not at all ergonomic but very easy in Haskell.
- the_duke 6y agoTrue. My biggest complaint there is actually lack of guaranteed tail call optimization.
- rudolph9 6y agoAn interesting development in Haskell is Linear Types. It opens the possibility of non-garbage collected Haskell. Still a lot of work left but it’s based on theory similar to that behind the Rust borrower mechanism (if I understand it correctly). https://www.tweag.io/blog/2020-06-19-linear-types-merged/ https://www.tweag.io/blog/2020-06-19-linear-types-merged/
- zozbot234 6y agoA "non-GC Haskell" would also need some way to make strict and lazy evaluation equally idiomatic and freely interchangeable in the language. Some general approaches are known that would clearly help with this issue e.g. "polarity" and "focusing", but the actual work of designing such a language has not been done.