8 ms·
Elixir 1.17 released: set-theoretic types in patterns, durations, OTP 27
- tiffanyh 2y agoHow does this compare to Gleam (strong) typing? https://gleam.run https://gleam.run
- throwawaymaths 2y agoGleam's type system is (IIUC) basically h-m bolted onto the beam. elixir's is its own
- weatherlight 2y agoDifferent type system with different goals. Gleam uses a modified version of the Hindley-Milner Type system. (Which is a rock solid tested type system.) A Set theoretical type system is more expressive(which suits the dynamic nature or Elixir better.) You can do Union and Intersection Types, and Negation Types, among other things, that you can't do with a HM type system. but it comes at the cost of how fast the program can be typed. HM types systems have amazing type inference capabilities and do so at O(n). Im not sure what the time complexity of the algorithm they are using to do the type checking for Elixir programs, but I bet it's more expensive than that. (Which is probably why they are rolling out the type system slowly.)
- tiffanyh 2y agoDoes Gleam check types at compile-time? And Elixir check types at run-time? (If at run-time, would that mean it would slow down your entire app as a result?)
- arrowsmith 2y agoElixir checks at compile time.
- bo0tzz 2y agoMy understanding is that the BEAM vm already has some (optional) runtime typechecks in the form of guards, which this new typesystem will also add for you automatically. And that these guards are actually used to speed things up, for example by JITing more optimized code.
- throwawaymaths 2y agoSo inserting those type checks automatically will cause regressions because those checks are not free at runtime, and there are cases where the JIT will look at the code and not bother optimizing.
- dub_gui 2y agoTo clarify, the type-checker does not modify compilation to the beam at all. Instead, it takes into account the predicted runtime checks to inject more static types into its analysis. For instance, without even introducing annotations, if a function head has a guard `is_boolean(x)`, using the + operator on x within that function would lead to a type error.
- throwawaymaths 2y agoexactly. The potential performance regression of guards is exactly why the elixir typechecker doesn't insert them. I guess I hadn't made that point clear in my comment. IIRC The elixir guides talks about excessive typechecking being a code smell.
- davydog187 2y agoBoth the Elixir and Gleam type systems run at compile time (and whenever you recompile during development) There are no plans for runtime checking AFAIK
- nerdponx 2y ago> A Set theoretical type system is more expressive(which suits the dynamic nature or Elixir better.) You can do Union and Intersection Types, and Negation Types, among other things, that you can't do with a HM type system. but it comes at the cost of how fast the program can be typed. I doubt that Python's static type hints existing within a formal mathematical framework, but it's interesting that intersection types have been under consideration for a long time now: https://github.com/python/typing/issues/213 https://github.com/python/typing/issues/213
- cobbal 2y agoHM is worst-case exponential, but it just happens to have good performance in practice.
- throwawaymaths 2y agoIt's also not clear that an h-m type system is what people want. For example, checking json inputs in gleam will always either be awkward or behind a "marshaller for me but not for thee" sort of inside-ball stuff, and the interface with other members of the beam ecosystem will be poor. It is possible to build a set theoretic type system without these problems, but I don't see these cases being handled by elixir's type system, either.
- deleted 2y ago[deleted]
- notemaker 2y agoReally impressed with how thoughtful _and_ fast they are delivering on their type system.
- widdershins 2y agoI'm really curious to know if many people with large Elixir problems are finding any issues with the new type system. This is pure curiosity, I don't have a dog in the fight!
- krnsi 2y agoJosé Valim already caught two bugs (one in Phoenix, one in Livebook) because of the type system: https://x.com/josevalim/status/1791409843888111667 https://x.com/josevalim/status/1791409843888111667
- bhaney 2y agoI'm excited about the type system so far, but I'm especially excited to hear about what else the type system is going to enable in the future. I remember José describing this as a "gradual gradual type system," where the gradual type system is going to be gradually added in stages, with this being the first stage. Any cool new type-system-related stuff coming up in the next few stages? I'm especially hoping for newly enabled compiler optimizations.
- neillyons 2y agoHere is the roadmap https://hexdocs.pm/elixir/main/gradual-set-theoretic-types.html#roadmap https://hexdocs.pm/elixir/main/gradual-set-theoretic-types.h... The next milestone will include a mechanism for defining typed structs.
- pawelduda 2y agoDoesn't gradual type system mean something else here? As in developers being able to iteratively add types while leaving untyped parts for later? At least this is how Ruby's Sorbet describes it
- mhanberg 2y agoCorrect, a gradual type system is a form of type system and not the method for rolling it out.
- arrowsmith 2y agoIt's a gradual type system that they're rolling out gradually.
- pjam 2y agoYes, but the discussion here was about it being a gradual, gradual type system, as in, the gradual type system being added gradually
- dub_gui 2y agoYou’re right about what a gradual type system means! A gradual type system allows flexibility in how you approach typing a codebase. It also means that your system incorporates a dynamic type, making your types 'gradual'. Interestingly, gradual set-theoretic types are flexible enough to let you gradually implement type inference for that system. Hence, the gradual gradual type system. :-)
- GiorgioG 2y agoSuper-excited for this release. I wish someone would put some resources into the Elixir IntelliJ plugin. I've tried, but I just can't enjoy using VSCode (vs IntelliJ based IDEs, Visual Studio, etc.)
- azurelake 2y agoSame. I would pay 50 / month for an Elixir plugin that had a comparable amount of polish to RubyMine.
- epiccoleman 2y agoAbsolutely agree. I love Elixir but the editor integration has always been unfortunately second-class. The happy paths in VSCode work well enough with the ElixirLS, but there are a few flaws that are a quite a bummer. One major one is no rename / refactor functionality (seriously?!) and a more Phoenix-specific issue is trying to contend with auto-complete in templates, which is no fun. I like VSCode fine, but I'd definitely be interested in a Jetbrains level IDE for Elixir stuff.
- cschmatzler 2y agoUse lexical instead of elixirls and most of your worries will be gone
- epiccoleman 2y agoOh man, I can't wait to try this out. Thanks for the pointer!
- mtndew4brkfst 2y agoIt frustrates me to no end that we have three separate, incomplete LSP implementations for Elixir, none of them collaborate and none of them are first party tools from the language maintainers - they're all minor community figures. They are one of the jankiest part of my experiences working with the language and it's very disappointing to live with when I also use rust-analyzer all the time and have seen the polished & productive version of LSP support.
- dimitrisnl 2y agoI'm very happy for this release. I picked up Elixir recently, and the missing a type system was my only pet peeve.
- sapiogram 2y agoDoes anyone know what they mean by "set-theoretic types"? I'm a PL nerd, but I've never heard this term before.
- kylecazar 2y agoThe original post Jose wrote announcing the gradual typing project has a good summary of the goal specific to Elixir (2022) 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...
- pjam 2y agoThere’s a paper about it, linked from the blog post: https://arxiv.org/abs/2306.06391 https://arxiv.org/abs/2306.06391
- bobwaycott 2y agoFrom the original paper[0]: > We present a gradual type system for Elixir, based on the framework of semantic subtyping ... [which] provides a type system centered on the use of set-theoretic types (unions, intersections, negations) that satisfy the commutativity and distributivity properties of the corresponding set-theoretic operations. The system is a polymorphic type system with local type inference, that is, functions are explicitly annotated with types that may contain type variables, but their applications do not require explicit instantiations: the system deduces the right instantiations of every type variable. It also features precise typing of pattern matching combined with type narrowing: the types of the capture variables of the pattern and of some variables of the matched expression are refined in the branches to take into account the results of pattern matching. [0]: https://www.irif.fr/_media/users/gduboc/elixir-types.pdf https://www.irif.fr/_media/users/gduboc/elixir-types.pdf
- williamdclt 2y agosounds like what typescript does, I'm not clear if the Elixir approach is different from "structural typing" (as TS calls it) or if they're rediscovering the same thing. Either way, I'm happy it's the way they're going
- pawelduda 2y agoThis is it, the final piece I wanted. Looking forward to the further stages. Apart from that, the language is 100% feature-complete as far as I am concerned.
- Tao3300 2y agoLast time I looked at Elixir, it seemed like the consensus was "you're going to need to do Erlang too". Is that still the case, or is dipping down into Erlang no longer required?
- theflyinghorse 2y agoAs elixir noob I find I reach into erlang often, mostly for things like sets, queues. Do people often end up writing erlang alongside elixir code in the same project?
- cess11 2y agoI'd say it's uncommon but you'll often use Elixir wrappers around OTP stuff or Erlang libraries. Sometimes there isn't a wrapper for the library you want so you'd just call into the Erlang library directly, which is much easier and "noob"-friendly than FFI:s usually are. For sets it's usually recommended to use Elixir MapSet. There is a Queue-wrapper around the FIFO-queue in OTP as well. For fun and learning you can also implement your own queues, or things like process pooling around the tooling already available.
- jasonpbecker 2y agoWe have a four year old application, 10+ developers, 2500+ PRs, and I don’t think a line of erlang has been written by us. Maybe there’s one or two instances of calling an Erlang function in Elixir, but we’re 94.7% Elixir, 3.7% HTML, 1.1% JS, and 0.5% Other in our monorepo, full application.
- rkangel 2y agoI occasionally end up reading Erlang so I can see what's going on in some library. I haven't had to write very much. If you have decent familiarity with Elixir, understanding Erlang isn't very difficult. You spend 20 minutes grokking the slightly weird syntax and then it's generally just a subset of Elixir. This is of course a bit of a simplification, but it's close enough for when you're trying to understand someone's Erlang code.
- neillyons 2y agoNice feature in this release is the addition of `get_in/1` which works with structs. eg. `get_in(struct.foo.bar)` If `foo` returns `nil`, accessing `bar` won't raise.
- mtndew4brkfst 2y agoIt was still possible to do this in prior versions of Elixir, just syntactically noisy. Any layer which isn't a vanilla map needs Access.key, as in: get_in(struct, [Access.key(:foo), :bar])
- skrebbel 2y agoBut that’s way less clear than just if struct.foo do struct.foo.bar else nil end
- mtndew4brkfst 2y agoSure, this snippet is a trivial example and doesn't sufficiently motivate get_in and family, which can be much more powerful when needs aren't so simple. It's also very hard to be as concise with more vanilla syntax when competing with put_in/update_in instead. The pattern and ability to generalize it is valuable IME.
- gregors 2y agoElixir and Erlang teams are absolutely killing it over the last few years, not to mention all the work done by the library and book authors out there. I've never been more excited about a release. I've been watching commits to both Elixir and OTP for awhile now and I feel Elixir/Erlang has really picked up steam. Thanks to everyone involved for making my life easier!
- aczerepinski 2y agoFor 10 years I’ve been reading about cool Elixir stuff here. Love the language. I gave up on finding a job in Elixir many years ago though after seeing salaries consistently lower than more mainstream languages. It may be the language I’d want to use most, but salary and cool product are more important to me than tech stack so it may never happen. Still fun to follow from afar.
- ch4s3 2y ago> seeing salaries consistently lower than more mainstream languages That seems surprising to me as an Elixir developer. Are you looking in the US, or elsewhere?
- davidw 2y agoI keep an eye out in the US and there just aren't many of them out there. And you have to be careful because some of those are * "Bob wanted to try out Elixir, so now we use it for this one microservice, but we're mostly a PHP/Rails/Java/Python/whatever shop and we'd like to rewrite it one day, because Bob left a few years ago" - places where someone wanted to play with something shiny and new. * Early stage firms where someone is a true believer that BEAM is some kind of magic scaling bullet or secret sauce.
- Tao3300 2y agoDammit that first bullet is giving me PTSD
- barrell 2y agoCan confirm, am early stage founder who is a true believer that BEAM is some kind of magic scaling bullet or secret sauce, currently looking for elixir dev. (mostly joking, if anyone is actually interested in ML, NLP, and Elixir, I have more pragmatic reasons for switching. Feel free to get in touch)
- acangiano 2y agoSalaries are consistently above other mainstream stacks, partly because most Elixir jobs look for senior engineers.
- deleted 2y ago[deleted]
- mike1o1 2y agoI've been using Elixir as a backend for a side project (with a Remix frontend) and it's been really pleasant and productive to work with on the backend. I appreciate how productive LiveView can be, but for my specific case I needed to handle poor network connections and LiveView was (as expected) a poor experience. I wish Elixir was able to decouple itself from LiveView in a sense in the minds of developers. Even without LiveView and realtime/channels, just using Elixir as a backend for a simple API has been really fun.
- manchmalscott 2y agoYou can use Phoenix without LiveView by running mix phx.new with the —no-live flag (or manually pull it out of an existing project).
- bnchrch 2y agoBut too the OPs point. This is not a technology that should be included by default. No matter how cool. Saying this as a die hard Elixir fan who's been using it since 2015.
- arrowsmith 2y agoWhy not? If you don't like it just build the app without LiveView. Having `phoenix_liveview` as a dependency in mix.exs doesn't do any harm if you're not using it.
- mike1o1 2y agoYes, I totally get that (and have been doing that). My complaint/suggestion is more around the marketing and messaging. There is so much more to Elixir than LiveView!
- barrell 2y agoI get this. Currently have a front-end built, with the need (& existing functionality) for offline local first etc. Switched to phoenix on the backend, and the amount of liveview stuff I have to 'wade through' is really distracting. It also seems to be eating up about 75% of the hype in the Elixir community :laugh:
- dankai 2y agoI've been building my startup 100% fullstack in elixir, and it's been the most wonderful technology I've ever worked with. I'm evangelising all my serious tech friends about how great it is. Now it would be awesome if rabbitMQ and its client would run on OTP 27, would love to upgrade :(
- Joel_Mckay 2y agoRabbitMQ is pretty solid, are you running into a performance leak or something? We've used the SSL cert client login method for years, and have been very happy with the reliability. Cheers, =)
- bglusman 2y agoSee announcement here https://www.rabbitmq.com/blog/2024/05/23/erlang27-support https://www.rabbitmq.com/blog/2024/05/23/erlang27-support
- Joel_Mckay 2y agoI guess we wait a bit more for a stable release. =)
- davidw 2y agoIf I may ask, what are you working on where Elixir hits the sweet spot compared to other technologies?
- dankai 2y agoA news aggregator (and premium news chatbot) that indexes and analyses around ~150.000 new articles a day (http://im.fo http://im.fo) I'm absolutely certain the real time processing would be unfeasible in any other technology in terms of complexity and the minimal compute resources it's running on. Modules like broadway, ash, oban, phoenix liveview ... make it not just a pleasure to work with but insanely performant. With over 20 years of programming experience, I can say with certainty that there is no language that makes me as productive as elixir. It's at least 10x my python productivity (despite being at an expert level in python as well).
- sergiotapia 2y agoCan't say enough good things about Elixir and Phoenix. Now with types coming, it'll get even better. By the way, you hear a lot about the BEAM and it's power - but in my experience you can go a LONG LONG LONG way before you ever have to even think about that part of your stack. Phoenix does such a tremendous job abstracting that for you. You just get the gainz with no effort. Other parts of the stack also just abstract that for you. Case in point: Oban. You get powerful, flexible and easy to use background jobs for essentially free. Right there in Postgres, with your Elixir code. It's crazy. Try it.
- mtndew4brkfst 2y agoI fully agree with you were it not for LiveView, which combined with the marketing obsession around LV, means people who could have glossed over OTP for a while longer are now confronted with it much earlier in their journey, possibly on their first controller route. Writing robust LiveView flows, and testing them well, is exactly as intellectually complex as writing stateful genservers with multiple non-linear flows and various call/cast entry points. LVs use different jargon and have small convenience layers like async-assigns, but mechanically genservers are literally what they are. I'd say that's crucial to understand well if you want to use them effectively. Love Oban and miss it deeply in other ecosystems.
- nelsonic 2y agoAwesome work Elixir & Erlang Devs! <3 Cannot wait for the "no types" excuse to go away for mass adoption of Elixir! Keep up the great progress.
- mikl 2y agoThe introduction of set-theoretic types has truly been a technical tour-de-force. A huge improvement of the language, but in a backwards-compatible fashion.
- deleted 2y ago[deleted]
- CaptainOfCoit 2y ago> This Elixir version introduces the Duration data type and APIs to shift dates, times, and date times by a given duration, considering different calendars and time zones. > We chose the name “shift” for this operation (instead of “add”) since working with durations does not obey properties such as associativity. For instance, adding one month and then one month does not give the same result as adding two months: I'm not exactly sure why adding one month and then one month would give a different result compared to just adding two months. Don't you in reality want the same thing? Why is "shift" more useful than "add"?
- bhaney 2y agoThere's a code example immediately after your quote specifically for addressing your confusion
- Tao3300 2y ago"One month" is a tricky unit because it's not always the same size. They have a good example right there. What's a month after Jan 31? Feb 28 or 29. A month after that? Mar 28 or 29. What's two months after Jan 31? Mar 31. Maybe you think it should behave otherwise, but they picked a way and changed the name so you wouldn't think of the addition operation and its expected properties.
- icedchai 2y agoThere are edge cases near month end. I once wrote a billing system for my own small business. If the customer signed up for a monthly plan near month end, on a day >= 28, their next billing date was always on the 28th to keep things simple.
- julienmarie 2y agoThe last few years the Elixir ecosystem has started to become the simplest solution to so many use cases: - Web development with Phoenix and Liveview is immensely enjoyable and fast - AI with NX, Axon, Bumblebee - Audio and Video streaming and manipulation with Membrane - CQRS and Event Sourcing with Commanded - Embedded with Nerves to make your own devices - Mobile apps with Liveview Native ( in development ) - Queues, pipelines and batch processing, etc... natively or with GenStage, Broadway or Oban depending on your use case but for me, the killer feature is IEX, Elixir's REPL. Being able to interact directly with my running code easily ( in dev or in production ), introspect it, debugging it, is just life changing. Adding types is indeed the last piece to the puzzle to bring even more confidence in the code we ship.
- theonething 2y ago> killer feature is IEX, Elixir's REPL Don't many other languages have this? Ruby has IRB for example. Is there anything IEX does that IRB doesn't?
- skndr 2y agoThe cool thing is that you can, with the BEAM, connect your shell[0] to a running server and use something like recon_trace[1] to watch functions as they’re getting called. The same principle is used for libraries like this distributed profiler so you can watch the aggregate performance of your application[2]. [0] https://hexdocs.pm/iex/1.12/IEx.html#module-remote-shells https://hexdocs.pm/iex/1.12/IEx.html#module-remote-shells (the remsh flag) [1] https://ferd.github.io/recon/recon_trace.html https://ferd.github.io/recon/recon_trace.html [2] https://hexdocs.pm/orion/Orion.html https://hexdocs.pm/orion/Orion.html
- 15155 2y agoThis was possible with various flavors of Pry and DRB once upon a time.
- cess11 2y agoNot just a running server, you can hook into a running cluster and do such things. The Observer, :observer.start(), is another very nice tool. Might require some widget libraries for the GUI but you'll likely have set that up on the machine you're doing the introspection from.
- auraham 2y agoAside note: Have any of you used elixir-desktop [1]? It is a wxWidgets + LiveView bundle, pretty much like a Electron app. In [2], Wojtek Mach explains how the team behind Elixir build Livebook Desktop. He explains how the project started, some subtle bugs found when building the app for MacOS, some limitations of wxWidgets in Windows, and many other implementation details. It would be awesome if the Elixir team releases something like elixir-desktop based on Livebook. That is, forking the Livebook repo and release an official template project for generating desktop applications based on LiveView. Right now, Livebook is distributed as an executable for Windows and Mac. Why not follow the same approach to allow developers to publish self-contained executables pretty much like Electron? I am aware of LiveView Native [3] but I think they follow a different direction. [1] https://github.com/elixir-desktop/desktop-example-app https://github.com/elixir-desktop/desktop-example-app [2] https://www.youtube.com/watch?v=Kiw6eWKcQbg https://www.youtube.com/watch?v=Kiw6eWKcQbg [3] https://native.live/ https://native.live/
- vohk 2y agoAny recommendations for an entry point into Elixir? I've been teaching myself Rust through resources like Rustlings and 100-exercises-to-learn-rust, and I've found that approach to be pleasantly accessible. I've yet to find something similar for Elixir, whether interactive or just well laid-out.
- ahamez 2y agoTry this book: https://www.manning.com/books/elixir-in-action-third-edition https://www.manning.com/books/elixir-in-action-third-edition!
- pjullrich 2y agoShameless plug: I created a video course that shows you how to build and deploy a product with Elixir really quickly. https://indiecourses.com/catalog/build-an-mvp-with-elixir-6i4V9yOqLL54GuG0HkV9HR https://indiecourses.com/catalog/build-an-mvp-with-elixir-6i...
- Vayl 2y agoHello Peter, fyi, I'm having trouble accessing the cashblog.app website. Not sure if it's just on my end but might be worth taking a look. Cheers.
- mtndew4brkfst 2y agoIf you're optimizing for career opportunities at all, Rust has more hiring potential than Elixir by a country mile. Both are lightly infested by web3 grift, though.
- cess11 2y agoBoot up a Livebook and step through some of the basics on the Elixir homepage. Someone else recommended Elixir in Action, which is a very good book once you have some grasp on the fundamentals.
- dub_gui 2y agoThis looks similar to what you describe: https://exercism.org/tracks/elixir/exercises https://exercism.org/tracks/elixir/exercises