x = random.choice([1, "foo"])
this is given as an example of why Python could never be strongly typed.Honest question: isn't this solved using Either in Haskell?
x = random.choice([1, "foo"])
this is given as an example of why Python could never be strongly typed.Honest question: isn't this solved using Either in Haskell?
#lang typed/racket
(: choose : (All (A) (Listof A) -> A))
(define (choose e)
(list-ref e (random (length e))))
(define x (choose (list 1 "foo")))
Unfortunately, people tend to assume that "type systems" and "the type system in Java/ML/Haskell" have the same level of expressiveness.The inferred languages just have this dude that watches your code and says, "yeah, I understand what is going on, your stuff is internally consistent"
For more on whether all programs have types, I wrote this: https://medium.com/p/8a3b4bedf68c
I agree with some of what you said in the medium link. Python does have a type system, structural and dynamic strong. The way the plus operator works was a mistake, Lua is superior in this regard.
Take a look at the type inferencing that Shedskin and RPython in PyPy can do. If there wasn't a type system, how are those 'static strong' programs created?
The programer and the program has a type system where the language may not.
As I say pretty explicitly in linked post, Python doesn't have a type system. Also, the term "strong" type system doesn't mean anything. Also^2, "structural" type systems are about how types are compared, and to whatever degree Python compares types, it isn't structurally.
RPython is a different programming language, which is statically type. Shedskin is similar.
RPython and Shedskin as not different languages, they are subsets. All programs in RPython and Shedskin are proper python programs with the same semantics.
Second, having a type system makes a language very different! Language subsets are different languages.
What you're saying is that Shedskin and Python have a non-empty intersection. But would the language of numbers with `+` be the "same language" as Python? It has the same relationship as Shedskin.
I made a mistake when I said quickcheck, I was thinking of the combination of Dialyzer and Typer in Erlang ( http://www.slideshare.net/konstantinvsorokin/kostis-sagonas-... )
I think I get what you are saying, that you have to take the totality of language in the current context.
And I would have to say yes, the language of numbers with "+" is in fact Python. I think it is also Haskell and lots of other languages. If I look at a corpus of language through a slit, I will always see a subset of that language. But it doesn't stop being that language by looking at with a microscope. What happens we see a code snippet like
a = 5 + b - 10
We don't know what language it is, but it doesn't matter. It is valid Ruby,Python,Lua,JavaScript, etc.Are we,me splitting hairs? I am just a layperson, I would like to fix any discrepancies in my knowledge.
You can achieve something like this with type classes, though. This is somewhat similar to requiring all the elements to fullfill an interface, kind of like List<Comparable> in Java-like languages. With existential quantification (there are other options) you can make a list where every element in a list can be of a different type as long as they derive from the same type class (like Eq, Ord, etc). The type class is still a constraint that Python doesn't have but it makes static typing possible.
See the heterogenous collection link above.