Re:Elixir and Phoenix can do it all
by loloquwowndueo on Saturday October 28, 2023 @05:24PM
(#38053509)
Elixir is not strongly typed. You can bind any data type to a variable at any time.
[ Parent
| on HN ]
Re:Elixir and Phoenix can do it all
by heisenzombie on Saturday October 28, 2023 @05:33PM
(#38053572)
Parent is making a distinction between “strongly” and “statically” typed. By some definitions. Type conversions in Elixir are generally explicit (contrast with JavaScript) and the type of a variable matters at runtime (e.g think about pattern matching), and so some people would call it “dynamic and strongly typed”.
This is not true.
For example doing "1" + 2 would give you an error.
Re:Elixir and Phoenix can do it all
by sodapopcan on Saturday October 28, 2023 @05:36PM
(#38053610)
You also can't do "foo" + "bar" to get "foobar", you have to do "foo" <> "bar" giving it even more type "strength" than many strongly typed dynamic languages have.
Re:Elixir and Phoenix can do it all
by arcanemachiner on Sunday October 29, 2023 @06:04AM
(#38057125)
Do you know if that was a conscious decision for that reason? I always wondered why that operator was used instead of a + sign.
Re:Elixir and Phoenix can do it all
by sodapopcan on Sunday October 29, 2023 @10:35AM
(#38058990)
I think it is pretty standard in functional languages not to overload operators. There may be technical reasons as well, I'm a bit out of my depth here, but it probably is better for performance with pattern matching knowing the type? Like `"hello " <> there = "hello there"`. Of course it's not just strings—concatenating lists uses ++ and for dates have their own functions.
OCaml takes it a step further with numbers where `+` only works on integers. You need to do `+.` to add floats. This lets it be statically typed without having to actually specify any types.
Again, a little out of my depth in terms of rock solid explanations.
But on the flip side you can also do "if my_var", which will evaluate to true for any non-nil value and non-false value
Re:Elixir and Phoenix can do it all
by sodapopcan on Sunday October 29, 2023 @02:42PM
(#38061364)
Is that a common source of typing errors? Genuinely wondering as I don't have a whole lot of experience with statically typed languages. I've personally never had a bug related to it.
I wasn't meaning to imply everything is perfect, though. For example equality operators take anything. I believe there may be changes coming around there.
Elixir doesn't technically have variables. Those are bindings: you give names to values. Variable would be more like a box storing a value.
Re:Elixir and Phoenix can do it all
by status_quo69 on Saturday October 28, 2023 @05:32PM
(#38053568)
Elixir is strongly typed, elixir is not statically typed
This is untrue.
https://thinkingelixir.com/elixir-in-the-type-system-quadran....
Re:Elixir and Phoenix can do it all
by arrowsmith on Saturday October 28, 2023 @06:13PM
(#38053892)
You're thinking of statically typed, which Elixir isn't. Elixir is strongly typed, which means something different.