Preferences

This is not true.

For example doing "1" + 2 would give you an error.


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.
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
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.

Do you know if that was a conscious decision for that reason? I always wondered why that operator was used instead of a + sign.
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.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal