3 ms·
I must have missed where they discuss the type system. They go to great length to explain that there aren’t classes, methods, etc. and showcase modules such as
by mberning 3y ago
I must have missed where they discuss the type system. They go to great length to explain that there aren’t classes, methods, etc. and showcase modules such as String, but it’s not clear to me how you know what can be passed to String.whatever.
- john_the_writer 3y agoNo classes, but there are types. When looking at the docs (which you'll do often) you'll see the doc. I say you'll be in the docs often because of things like Enum.map which returns a List not a map Enum.map_reduce takes either a List or a Map, but returns a List. Kernel.get_in takes a Map and a List
- ch4s3 3y agoThe basic data types work with modules of the same name generally. String module functions work on UTF8 but strings. If you aren’t sure you can run the h() function in an ice shell on the module and function, e.g. h Kernel.+ or whatever.
- ollysb 3y agoElixir doesn't currently have a type system built into the compiler. There is a separate package Dialyzer which does type checking but it would be fair to characterise it as a bolt-on rather than part of the core tooling. Work is now underway[1] to create a type system based on "set-theoretic types" though this is still considered experimental and may never be added to Elixir. [1] https://elixir-lang.org/blog/2022/10/05/my-future-with-elixir-set-theoretic-types/ https://elixir-lang.org/blog/2022/10/05/my-future-with-elixi...
- bobwaycott 3y agoThe type system has moved from the research phase to in development: https://elixir-lang.org/blog/2023/06/22/type-system-updates-research-dev/ https://elixir-lang.org/blog/2023/06/22/type-system-updates-...
- pavel_lishin 3y agoMy experience with Dialyzer wasn't great a few years ago. The error messages are often counter-intuitive, to the point where hating dialyzer became a meme at work.
- biql 3y agoTrying Gleam that also runs on Erlang VM but has static types, a fast compiler with Rust-style elaborate error messages made me hopeful about how much nicer this experience can be when static types are added to Elixir too.
- bobwaycott 3y agoI’ve always found dialyzer errors to be quite straightforward and easy to understand—the challenge is finding where a poor typespec originates in a codebase (or dependency) with poor typespecs.
- totallymike 3y agoI imagine they expect that if you’ll be using Elixir at any capacity, you’ll have the docs in front of you, which details all the functions available in the modules, as well as the parameters they expect. https://hexdocs.pm/elixir/1.15.4/String.html https://hexdocs.pm/elixir/1.15.4/String.html