The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
What I'd like to do is to say, okay, so if all else fails, then at least you can, as it were, pair up a value with its type representation.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
There's one reason we don't want to interpret an integer as a double-position float, for example, is that they don't even have the same representation, which is just nonsense.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
One possible way, which untyped languages let you do, is to tag every integer in every double-position float with the fact, I'm an integer, I'm a double-position float.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
That has a lot of overhead.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
So one merit, I think it's not the biggest single merit, it is a major merit of static type systems, is you have no tags.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
You know that if it says it's an integer, it's going to be an integer.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
You know that if it's a double precision float, it's going to be double precision float.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
But if you're not sure, maybe we could make a way to make a pair of a type representation and this value.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
The type representation is now like a runtime tag.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
It's like a little runtime data structure that describes the type.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
And then in your program, you could say, now I want to say, oh, I've got this type dynamic.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
We'll call this pair a value of type dynamic.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
Now, when I want to take a value of type dynamic and treat it as a character, I want to say, oh, look, look at the type dynamic.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
See if it says it's a character.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
If it is, return the character.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
If not, crash.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
Like runtime failure.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
That's fine.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
You can do that.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
And Haskell has good support for dynamic typing where necessary.