I would summarize my view of the type annotation proposal as follows: Statically typed languages can introduce inference heuristics that minimize the amount of type declarations. They can "jump" into the dynamically typed world more easily. The other way around is a lot harder. Not only are all those type annotations lacking in the standard library and the tools around, but there is also a lack of function design by types.
Revenge of the Types
71–80 of 137 posts
Re: Revenge of the Types
#72If the author is reading this thread, I spotted this type-o: Type type claims that it's a subclass of object.
Is that a typo? I read that as '[The type named] "type" claims that it's a subclass of object' Compare to "Type integer claims that it's a subclass of number."
Re: Revenge of the Types
#73Earlier quoted context omitted.
Try running "import UnitTyped.NoPrelude" first. EDIT: you may also want to start ghci with the "-XNoImplicitPrelude" flag, or explicitly disambiguate operations such as "*" with "UnitTyped.NoPrelude.*" or "Prelude.*"
Thanks, but that's not enough. The error seems due to the fact that `meter` is passed as an argument to `1` which is not a function, and indeed I don't see how that could be valid haskell code (unless there's some language flag I should enable, but unfortunately the wiki/docs of unittyped doesn't seem to be comprehensive enough)
To answer the question of how it is possible, we can start by looking at the types. ":t" is a ghci command to show the type of an expression:
ghci> :t 1
1 :: Num a => a
This indicates that "1" can be any type that implements the "Num" typeclass.Next, we want to determine what type "1" takes in the expression "1 meter". We can do this with:
ghci> let a=1; b=a meter
ghci> :t a
a :: UnitTyped.Value Double LengthDimension Meter
-> UnitTyped.Value
Double
('UnitTyped.UnitCons
* Length ('UnitTyped.Pos 'UnitTyped.One) 'UnitTyped.UnitNil)
Meter
We can see that, in the expression "1 meter", "1" is actually a function. Looking at the source code [1], it seems like this is accomplished in a relativly hacky manner: instance (Fractional f, Convertable a b, t ~ Value f a b) => (Prelude.Num (Value f a b -> t)) where
fromInteger i x = Prelude.fromInteger i . x
(+) = error "This should not happen"
(*) = error "This should not happen"
abs = error "This should not happen"
signum = error "This should not happen"
This works because the "+" being defined here is Prelude.+, not UnitTyped.NoPrelude.+ (which is defined seperatly).[1] https://hackage.haskell.org/package/unittyped-0.1/docs/src/U...
Re: Revenge of the Types
#74Earlier quoted context omitted.
"But for building a robust application that will have to be maintained a long-time, you have to religiously write tests in these languages or you'll be buried in bugs. And even then, you still may be buried in bugs that a static, strongly-typed language would have detected." People make this sort of claim all the time, but my personal experience has not borne it out, and I have seen no data to backup this claim which…
If you value time spent writing code higher than preventing bugs, I have doubts about the size of codebases you were maintaining. The reality I have experienced is that working with a large codebase in Python (talking 100kloc+ here, and teams larger than 3) is an absolute nightmare. Lack of explicit typing on argument values and returns means that everytime you add an argument to a function, or move things around, yo…
In my opinion, the maintainability of a codebase is not that much a function of the language, but of the architecture and structure of the code.
Re: Revenge of the Types
#75Earlier quoted context omitted.
I think Armin didn't address these valid points, because as he points out, "The first one is that I barely understand them[type systems] at all myself."
Seems odd for someone who doesn't understand type systems to be writing a high profile blog post about why they don't belong in Python, no?
Hopefully Armin listens to people who have been thinking about this for a long time, and done work in this area. But why should his ideas, which are admittedly uniformed, get spread wider than better ideas? This happens a lot anyway.
I don't think it's entirely positive when people rant when they don't have the knowledge to back it up. However, it can produce a reaction from other people to step up and argue their case better. Or even better, to put out their code. I think in this case Armin does have a bit of a clue, and this essay is informing himself, and others quite well.
You can statically check python with types now (pycharm pysonar2 etc), and you can use things like ABCs and interfaces to enforce constraints.
"Union types" and "intersection types" are the type systems people have used to statically type check python, and other dynamically typed languages. You can see the various types coming into or out of a function. This is what Armin is talking about with Option/Composite types.
So these various type systems which have been used to add extra type checking on top of python are now being blessed, and brought into the language proper.
There are plenty of places in Python where the types are not specified well, because mostly it doesn't matter to people using it. Since the type checking tools have added external type definitions, and fixed up inconsistencies outside of the python implementations. So Armin is pointing out a few examples of type inconsistencies within python. There are lots more. Especially at the C API level, where things are a bit weird. But they haven't really bothered people that much, so they haven't been fixed. As someone who has written C extensions for python, I can tell you that it is weird, and things have changed with every python release (even, and especially in the 2.x series).
However, these external type definitions are being brought together into the language (as per Guidos email) in the mypy format. There is a hope that the other definitions from tools like PyCharm can be translated automatically. These definitions are being used in useful tools today.
These external type definitions are in effect a specification of the types for the core language, the standard library, and even other popular libraries (like Django etc).
What came first the Duck or the specification of the Duck?
Re: Revenge of the Types
#76Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…
class Metric {
static function main() {
var coinRadius:Millimeters = 12;
var myHeight:Centimeters = 180;
var raceLength:Meters = 200;
var commuteDistance:Kilometers = 23;
diff( coinRadius, myHeight ); // 1.788 meters
diff( raceLength, commuteDistance ); // 22800 meters
sum( commuteDistance, coinRadius ); // 23000.012 meters
}
static function diff( a:Meters, b:Meters ) {
var d = Math.abs( a-b );
trace( '$d meters' );
}
static function sum( a:Meters, b:Meters ) {
var s = Math.abs( a+b );
trace( '$s meters' );
}
}
And the best part is, at runtime those are all floats. Take a look at the compiled JS code: (function () { "use strict";
var Metric = function() { };
Metric.main = function() {
var coinRadius = 12;
var myHeight = 180;
var raceLength = 200;
var commuteDistance = 23;
Metric.diff(coinRadius / 1000,myHeight / 100);
Metric.diff(raceLength,commuteDistance * 1000);
Metric.sum(commuteDistance * 1000,coinRadius / 1000);
};
Metric.diff = function(a,b) {
var d = Math.abs(a - b);
console.log("" + d + " meters");
};
Metric.sum = function(a,b) {
var s = Math.abs(a + b);
console.log("" + s + " meters");
};
Metric.main();
})();
The compiler takes care of all the conversions for you. To see the complete compileable example, including my type definitions for each unit, take a look at this gist: https://gist.github.com/jasononeil/b6b1845824f45f5d19dfAnd the manual on abstract types: http://haxe.org/manual/abstracts
Re: Revenge of the Types
#77"Because there is basically no type system that fights against you, you are unrestricted in what you can do, which allows you to implement very nice APIs." If you feel like the type system fights against you, chances are that you are doing something wrong. When I program, the type system definitely fights for me. It gives me a lot of guarantees, plus it's a really convenient way of self-documentation. I mean, I'm not…
Re: Revenge of the Types
#78Earlier quoted context omitted.
Thanks, but that's not enough. The error seems due to the fact that `meter` is passed as an argument to `1` which is not a function, and indeed I don't see how that could be valid haskell code (unless there's some language flag I should enable, but unfortunately the wiki/docs of unittyped doesn't seem to be comprehensive enough)
Weird, it is enough on my machine (running ghc 7.6.3, unittyped 0.1), but unittyped does seem to use a lot of language extensions internally, it is seems possible that it would behave weirdly on different versions. To answer the question of how it is possible, we can start by looking at the types. ":t" is a ghci command to show the type of an expression: ghci> :t 1 1 :: Num a => a This indicates that "1" can be any t…
https://bitbucket.org/xnyhps/haskell-unittyped/issue/3/num-i...
Btw, it's weird... I just tried
ack-grep "Num\b"
and I cannot see any instance of Num defined anywhere inside unittyped's srcPS: ok, since I wanted to see exactly what was the problem with unittyped compiling under ghc7.8 I cloned the sources, but I forgot to checkout the actual release... thus running directly from tip was the cause
Installing it directly from hackage solved it, it's embarrassing how I was stunned by this in hindsight
Re: Revenge of the Types
#79Earlier quoted context omitted.
>If you feel like the type system fights against you, chances are that you are doing something wrong. Like most things, I think this depends on context. Doing exploratory data analysis in a static, strongly-typed language, for example, is extremely painful. And writing quick, one-time scripts in such languages is usually more trouble than it's worth. For this reason, Python is a wonderful language for doing data anal…
"But for building a robust application that will have to be maintained a long-time, you have to religiously write tests in these languages or you'll be buried in bugs. And even then, you still may be buried in bugs that a static, strongly-typed language would have detected." People make this sort of claim all the time, but my personal experience has not borne it out, and I have seen no data to backup this claim which…
There have been attempts at measuring the effect of type systems, see for example this excellent presentation for some references: http://www.slideshare.net/Felienne/putting-the-science-in-co.... One of the studies mentioned here does claim that, other things being equal, static typing helps find bugs quicker.
Re: Revenge of the Types
#80I've been using Nimrod to replace Python on a Bitcoin project. elliptic.nim: https://github.com/def-/bigints/blob/master/examples/ellipti... elliptic.py: https://github.com/wobine/blackboard101/blob/master/Elliptic... Nimrod looks and feels like python, but it compiles to C. It's like C except with Pythonic syntax and with Boehm GC optional. In addition, Nimrod has a burgeoning NPM-like module ecosystem developing, a…
http://ivoras.sharanet.org/blog/tree/2013/Oct-2013-10-05.wha...
Type inference:
http://nimrod-by-example.github.io/variables/type_casting_in...
Quick introduction for C programmers:
https://github.com/Araq/Nimrod/wiki/Nimrod-for-C-programmers