Replies: 1 comment 6 replies
-
This really is a lovely idea, but the story is a bit more complicated than this. The problem starts with higher order functions. Take for example More general effect systems exist. But if you'd only like to track (im)purity, this paper about Boolean effect polymorphism in the Flix language is exactly what you want. |
Beta Was this translation helpful? Give feedback.
-
When reading Elixir in Action there was some notice box about Elixir being impure. I don't mind impurity but it would be great to know what you are working with.
So I'd love following pragmatic approach if it makes sense. Gleam's compiler cannot for FFI calls know if something is impure or not. So by default it should flag those as impure.
But the programmer could declare for FFI that they are pure.
A standard gleam function is marked as pure by the compiler pure if:
In consequence as of most of stdlib is unpure. But with a little work on the FFI calls and declaring those as either pure or impure explicitly we'd have a whole stdlib where people would know from the LSP if the whole call is pure.
I'd say - except for function's with
todo
where if no keyword is given a function is considered impure, if pure is given it is considered pure - purity is checked and inferred by the compiler, so if it is given explicitly by the programmer, a compile error will occur if purity declaration does not match.The compiler could even flag hole modules as pure (if all functions are pure) and yield that into the generated documentation.
This way it makes it easier for the programmer to separate libraries and applications in parts that are pure such as algorithms/transformers etc. and parts that deal with side effects, and potentially keep the side effects very separated.
It might also help a lot with unit testing because pure functions are easier to test AFAIU.
Beta Was this translation helpful? Give feedback.
All reactions