4 ms·
I like Elixir and all of its infrastructure and libraries, like BEAM and Phoenix, but I could never get used to not having static types. What's the best way to
by cercatrova 7y ago
I like Elixir and all of its infrastructure and libraries, like BEAM and Phoenix, but I could never get used to not having static types. What's the best way to have static types in Elixir?
I have seen in Elixir an implementation of functional programming concepts that might prove useful: https://github.com/witchcrafters/witchcraft https://github.com/witchcrafters/witchcraft. It hasn't been updated since last year so I'm not sure if it still works.
These days I've just started using Rust and actix-web instead, seems a lot faster due to no VM, with static typing, and moreover, algebraic data types. I wonder if I could use another language without ADTs anymore.
- skrebbel 7y agoSame. I suffer through it, because the rest is pretty neat. There is no best way. Fortunately the Elixir core libraries are annotated with typespecs, which gets you like 30% there. But dialyzer sucks, and the typespec syntax itself, as well as its expressiveness, leave a lot to be desired. It's clearly an afterthought. One day I'm gonna make a TypeScript for Elixir. Note: There's eg Gleam a statically typed language for BEAM, but it's quite unlike Elixir and it has a much smaller community. https://github.com/gleam-lang/gleam https://github.com/gleam-lang/gleam. I doubt using eg Phoenix on Gleam is possible, or if it is, whether it's fun. It looks promising though, especially if you're into Ocaml/Haskell-style "hard" FP.
- midgetjones 7y agoGleam is pretty young, so I wouldn't expect the community to be huge. Not sure what you mean by 'Phoenix on Gleam', but you could write core code in Gleam and use it in an Elixir/Phoenix app, no probs https://dev.to/contact-stack/mixing-gleam-elixir-3fe3 https://dev.to/contact-stack/mixing-gleam-elixir-3fe3
- skrebbel 7y agoI just mean "how easy would it be to common Elixir libraries from Gleam, especially if they're rather involved like Phoenix". Like, quite some of the more popular Elixir libraries (eg Phoenix and Ecto) depend quite heavily on macros, which I assume sortof rules out using them from other languages. Like Elixir itself, I think Gleam will only really shine once a community builds its own libraries for non-trivial messy stuff such as DB layers and web frameworks for it. The interop is be great for simple functional stuff though, like unicode converters, JWT libraries and AWS wrappers.
- deleted 7y ago[deleted]
- lpil 7y agoHi! I'm the author of Gleam, thanks for your interest. For how young we are I think we're doing a good job of building a community, there are more familiar faces in IRC and on GitHub every day. My goal is for Gleam to be easier to use than Elixir, and in many ways we are taking inspiration from Elm which excels here. Hopefully in the future Gleam will meet your needs! :)
- hopia 7y agoGleam seems like effort in the right place, I'm looking forward to seeing it in the wild! Since we got you here, can you tell us what's your plan with static type checking for message passing semantics? From what I understand, that's the hard part about producing a static type checker for BEAM systems. As for things like gen_server, is the idea currently that you simply give type definitions to callbacks, allowing the gen_server to model its state with types? At first glance, I also don't understand yet how parametric polymorphism works. Is it implemented at language level?
- lpil 7y agoWitchcraft works well but it's not statically typed. It uses the patterns of Haskell but they are checked at runtime. I'm working on a statically typed programming language in the Erlang VM called Gleam. It's very young but perhaps one day it will meet your needs! https://github.com/gleam-lang/gleam https://github.com/gleam-lang/gleam
- cercatrova 7y agoI've used Gleam back in the 0.1 or 0.2 days, back when you posted about it on the Elixir forum, glad to see it's still moving along nicely!
- reledi 7y agoDefinitely. When I go back to Elixir from Go I feel the pain of not having static types. AFAIK, the closest we have right now is - typespecs - guard clauses - structs w/ required keys (cannot specify types) - ecto embedded schemas (e.g. structs with "typed" fields)
- dudul 7y agoAfter using Elixir for almost a year professionally, I find structs/schemas to be fairly useless when it comes to type safety. These are essentially just maps, there is absolutely no guarantees, anywhere in your code, that your map was created properly, and went through the proper set of validations. When I get a `Point` struct, I have no guarantee that the wrapped lat/long are actually valid. After 15 years of static typing this is just so stressful :)
- conradfr 7y agoI don't care that much between dynamic and strict types but I like strict typing. So yeah typesecs and guard clauses cover a lot of that (and the ever fun dialyxir) but it's more cumbersome than just typing your function parameters and variables. And funnily enough in the end what I miss the most is the type hinting when I write function calls. I use Intellij and the elixir plugin doesn't support that AFAIK, it's a real productivity killer.
- Zalastax 7y agoWe're working on a gradual type system for Erlang which also works quite okay for Elixir: https://github.com/josefs/Gradualizer/ https://github.com/josefs/Gradualizer/.
- GordonS 7y agoSame here. I spent a day learning and playing with Elixir around a year ago, and immediately liked it a lot. But more main dev language is C#, and I'm very used to static typing - as much as I enjoyed Elixir, the lack of static typing was a problem for me, so unfortunately I chose not to take it any further.
- lawik 7y agoI think there is work to get static typing in Erlang. This tweet thread was where I stumbled into it: https://mobile.twitter.com/slashdotdash/status/1238513622189584386 https://mobile.twitter.com/slashdotdash/status/1238513622189...
- toastal 7y agoThere's purerl, a PureScript compiler to Erlang as an option of types to something on BEAM. I can't comment about it's maturity but it the Pinto + Stetson libraries seem like an interesting take.
- brightball 7y agoStatic typing will create a lot of problems in a BEAM language IMO. The distributed nature and ability to send calls to other nodes that can be running completely different code would throw it for a loop unless you had a way to get the types from the other nodes as well. And even if you could there are a number of synchronization problems that come from it. You’ll end up getting the static benefits on your single node, but beyond that those guarantees will be gone just like interacting with a REST API.
- cercatrova 7y agoCouldn't it work like GraphQL which is typed?
- dognotdog 7y agoIt's interesting, I started out seriously programming in C++, then took to Smalltalk, Lisp, Io, as exploratory languages, doing more work in ObjC, and eventually Erlang and now Elixir, and I do like the Elixir compromise of some typechecking, though indeed it is a little cumbersome. Especially doing embedded work, and without doing proper mockups and test driven dev, the turnaround time with uploading code, rebooting the device, and waiting for a runtime error is quite long, and more compile-time error checking could help. However, I also feel like types are more important to JITs and compilers optimizing high-performance numerical code, and dropping to C to do that with Elixir's FFI is thankfully simple enough. I'm quite ok with Duck-Typing, as it does help me to iterate fast, even if it doesn't help the computer go fast :)
- cercatrova 7y agoI use TypeScript a lot and I only write in transformations of types in functions, rather than classes, so having ADTs is a big part of my workflow. I also write Python for machine learning but that's more glue code for Tensorflow, not full applications. I feel like once you go to FP land it's hard to come back :D