3 ms·
Why can't we have a language that supports both? I would love to have a language with a scalable type system where I could hack out a quick small prototype with
by nradov 16y ago
Why can't we have a language that supports both? I would love to have a language with a scalable type system where I could hack out a quick small prototype with dynamic typing first, and then perhaps layer on static types later where necessary to improve reliability and performance as the program evolves. For example, I would like to be able to declare a variable in all of the following different ways.
a value
a number
a rational number
a rational number between [0.0 - 1.0)
a rational number between [0.0 - 1.0), and I don't need any more than 30 bits of precision
a rational number between [0.0 - 1.0), and I don't need any more than 30 bits of precision, and please try to optimize for minimum memory usage instead of performance
- swannodette 16y agoYou can support both. You should take look at Typed Racket, Racket w/ Contracts, Erlang Dialyzer, and Qi/Shen. Frankly the Lisp contingent is way ahead on this kind of thinking (would of course love to hear about others). I'm interested in developing such systems for Clojure and have actively researching something considerably more powerful than Chambers/Chen predicate dispatch.
- Confusion 16y agoQi/Shen is a fusion of Haskell and Lisp, heavily inspired by Haskell. The Lisp contingent is not 'way ahead': they are simply assimilating useful bits of their strongly typed functional cousin languages.
- michaelcampbell 16y agoI'm not experienced enough to say that you absolutely can, or cannot. I only have some experience to guide me, and I haven't seen it done yet. That said..., I have an uneasy feeling that trying to do it would end up with a PL/1 type of situation where, depending on your background, you write it with whatever baggage you bring with you, and the language would get large to the point of different types of programmers writing in their own familiar subset of the language. Or, I'm completely wrong. =)
- anamax 16y ago> a rational number > a rational number between [0.0 - 1.0) Those are representation errors. The hard problems that I run into rarely have much to do with representation. The hard problems are knowing when it's okay to add apples and oranges and when it isn't.
- zoul 16y agoYou might be interested in the type system of Perl 6: subset Filename of Str where { $_ ~~ :f }; Here you define the Filename type as a string that represents an existing path. This particular example is a horrendous hack of course, but the tool looks very interesting. Not sure if this can be used for performance tuning in existing P6 implementations.
- rjh29 16y agoThat's a horrible hack indeed :) Perl 6 does have 'gradual typing' though. You can define a variant: my $foo; or a typed variable: my Int $foo; or a subtype with arbitrary restrictions subset OneToTen of Int where { 1 <= $^n <= 10 }; my OneToTen $foo; Or... (http://rosettacode.org/wiki/Define_a_primitive_data_type#Perl_6 http://rosettacode.org/wiki/Define_a_primitive_data_type#Per...) subset Prime of Int where { $^n > 1 and $^n %% none 2 .. sqrt $^n }; Perl 6 scares me.
- edabobojr 16y agoIt's been a long time, but I believe Ada provides the ability for the first 4 and I would bet you could define the last two in it.