3 ms·
Using Either in Haskell would require changing the program a little to add injections. But that exact program (modulo syntax) can be written in Typed Racket:
by samth 13y ago
Using Either in Haskell would require changing the program a little to add injections. But that exact program (modulo syntax) can be written in Typed Racket:
#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.
- sitkack 13y agoI just realized that all programs have types and type systems. Some dynamically typed programs have hairy n-dimensional fractal type systems that no human would ever figure out (usually from bad code). 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"
- samth 13y agoWell, I don't think that's correct -- it would make the term "type system" meaningless. In particular, lots of programs have bugs that type systems can catch. For more on whether all programs have types, I wrote this: https://medium.com/p/8a3b4bedf68c https://medium.com/p/8a3b4bedf68c
- sitkack 13y agoI don't think it makes the standard definition of "type system" meaningless. Maybe what I am referring to above is a "type space". 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.
- samth 13y agoWhat is a "type space"? 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.
- sitkack 13y agohttp://stackoverflow.com/questions/2351190/static-dynamic-vs-strong-weak http://stackoverflow.com/questions/2351190/static-dynamic-vs... RPython and Shedskin as not different languages, they are subsets. All programs in RPython and Shedskin are proper python programs with the same semantics.
- samth 13y agoFirst, as the second answer points out, the terms "strong" and "weak" shouldn't be used and are confusing. Second, having a type system makes a language very different! Language subsets are different languages.
- sitkack 13y agoSo when I use quickcheck with Python or Erlang I am creating a different language? Linguistically I don't understand how a proper Shedskin program which is also a Python program with the same semantics is in another language. By that definition, the runtime system effects what the language is, but this happens after it is written, so how can it do that?
- samth 13y agoNo, quickcheck is a testing tool, not a type system. It never rejects your program. 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.