Conversation
|
Hi @Defman21! There are some caveats here. Let's convert your example to regular types. Imagine this function: You could give it a type signature of shape: But you could also give this one: The last one is not wrong but it is imprecise. In that version, we can pass Note your example could also be satisfied by a function of shape I will sleep on this and see if I can come up with a simpler example with fewer caveats. |
|
Hi José! First of all, thanks for taking your time explaining this stuff to me :)
And if I understand correctly, any function with one of the following signatures would satisfy the spec (if we combine all Which is much broader and have improper variants rather than a function that has both of these signatures: Which is precise (I've just watched your talk about precise typing @ ElixirConf 2026 :D). Your I mean, Elixir is kinda unique because you have multi-head functions with guards and I'm not sure it's possible to express such uniqueness in other mainstream languages and their type systems. I can only come up with something like I'd be interested to see what example you can come up with, if any :) |
Yes, correct. The biggest issue though is that Elixir cannot distinguish between a function of (int -> int) vs (bool -> bool) at runtime, so the All of those things are interesting but I think it is a bit out of scope of what we are trying to introduce in this section! |
Okay that's fair, it's just set theoretic types caught my attention because the whole documentation was an interesting read and I was stuck for a while with multiple function heads. Thank you again for explaining it in such great details! <3 |
While I was reading about set theoretic types, I didn't fully understand the reasoning behind functions with multiple heads being
ANDed in their type definition. The t-shirt example helped a bit, but what made it click for me is the example I've described in the Pull Request: a function that takes a list of integers or booleans and a function to map every value of the list to some new value. So I'd like to contribute such example to the documentation in case it would help someone as well :)English is not my native language so the wording may not be top notch, feel free to re-word it.