Type of "not a number" is number
This is a really good interview, and does a good job highlighting Javascript's biggest strength: it's flexibility.
“It was also an incredible rush job, so there were mistakes in it. Something that I think is important about it is that I knew there would be mistakes, and there would be gaps, so I made it very malleable as a language.”
He cites the “discovery” of asm.js inside of JavaScript, calling it “another thing I’m particularly proud of in the last 10 years.” It uses the bitwise operators that were included in the original JavaScript which are now the basis for a statically-typed language with machine types for high-speed performance. “If it hadn’t been in there from 1995, it would’ve been hard to add later. And the fact that it was there all along meant we could do incredibly fast JavaScript.”
He tells InfoWorld it’s “this very potent seed that was in the original JavaScript from the 10 days of May in 1995.” JavaScript’s 32-bit math operators (known as bitwise operators) trace their lineage all the way back to the C programming language — and to Java. This eventually led to WebAssembly — a way to convert instructions into a quickly-executable binary format for virtual machines — and the realization that with a JavaScript engine, “you can have two languages — the old language I did with the curly braces and the functions and the shift operators, and this new language which is a binary language, not meant for reading by humans or writing. But it can be generated by compilers and tools, and can be read by tools…”
This is my favorite language: GHC Haskell
GHC Haskell:
GHCi> length (2, "foo")
1
Wait, now I need to know why.
* some time later *
I went to check why the hell this happened. It looks like the pair ("(,)
") is defined as an instance of Foldable
, for some reason, which is the class used by functions like foldl()
and foldr()
. Meanwhile, triples and other tuples of higher order (such as triples, quadruples, ...) are not instances of Foldable
.
The weirdest part is that, if you try to use a pair as a Foldable
, you only get the second value, for some reason... Here is an example.
ghci> foldl (\acc x -> x:acc) [] (1,2)
[2]
This makes it so that the returned length is 1.
Oddly enough, in Haskell (as defined by the report), length is monomorphic, so it just doesn't work on tuples (type error).
Due to the way kinds (types of types) work in Haskell, Foldable instances can only operate over (i.e. length only counts) elements of the last/final type argument. So, for (,) it only counts the second part, which is always there exactly once. If you provided a Foldable for (,,,) it would also have length of 1.
Feels like it could be one of those facebook posts to test "smart" people. Only the top 1% of people can answer this simple math question: "11" + 2 * 2 - 3
Programmer Humor
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics