3 ms·
Kind of, but not really. The combination of type classes (traits in Rust) and HKTs in Haskell mean that you can quite easily restrict a function to only be abl
by lomnakkus 8y ago
Kind of, but not really.
The combination of type classes (traits in Rust) and HKTs in Haskell mean that you can quite easily restrict a function to only be able to do a subset of what's possible in "the world".
A trivial example would be
foo :: Logger m => Int -> m ()
where Logger is a type class (trait in Rust-speak) which implements the Monad type class (thus allowing 'imperative'-style programming), but also has a "log" method which allows the program to emit a string to the log.
The thing is that given the restrictions of parametric polymorphism that function 'foo' has to work for any Logger instance we give it, so it absolutely cannot do anything other than pure computation or invoking the "log" method. It cannot do any other side effects at all. So, it's not "pure", but it's also much more restricted than "impure".
That's a very powerful tool for modeling highly effectful systems.