Elixir's intersection types
ฝัง
- เผยแพร่เมื่อ 13 มิ.ย. 2024
- Elixir is exploring the idea of adding types. During ElixirConf 2023, José Valim talked about the need for an intersection type when specifying types for certain Elixir functions. I checked out the research paper to understand more. Here, I show why we need that type.
For more videos, check out www.elixirstreams.com - วิทยาศาสตร์และเทคโนโลยี
Thanks, I was a bit confused, and your video really clarify that!
So glad to hear that!
Thank you, I was confused as well and this cleared it up very nicely!
Glad to hear it!
I hope that it will be possible to separate the type per each function clause and automatically make all function clause's types are combined with an "and". It will be a lot cleaner.
That reminds me a lot function overloading
Where can I see the video presentations they made on the type system at ElixirConf 2023?
th-cam.com/video/giYbq4HmfGA/w-d-xo.html
2:48 I haven’t watched the talks yet, but I’d really appreciate if we could provide a type specification for each of the function’s heads:
$ integer() -> integer()
def negate(x), do: …
$ boolean() -> boolean()
def negate(x), do: …
Yeah, that would be nice. I don't know if there'll be limitations around that, but I like that we can at least break it into multiple lines. It makes it read very nicely.
José mentioned that you can format the type either way - all at the top, or above each head.
My understanding after watching Jose's video was that you could do this
Like your concise videos, and of course Elixir. Gonna be your 667'th subscriber to break the 666 here 😆
Thanks for looking out for that number! 👀 😂
I still don't see why this is necessary. The guard clause clearly indicates what type of data the function accepts. I just hope Elixir doesn't turn into something similar to TypeScript.
The guard clause specifies data at runtime. Types would do it at compile time. I too am worried about what types will mean for Elixir, but I know José and team are very careful in their approach. So, I think we'll land with something good -- if they land at all.
@@germanvelasco Oh now I see. I like the simplicity of $ integer() -> integer(). If they go with this approach I hope it replaces typespecs. It's a lot easier on the eyes. Elixir is not perfect and has flaws like any other language but I love it's simplicity and expressiveness. It's the only language I've been able to understand at a high level. I hate to see that go away by introducing more complexity to the language. Thanks so much for all of your contributions to Elixir and keep up the good work :)