4 ms·
> There is nothing special about map and filter, they are not idiomatic Python because there are better ways to do the same things. True, list comprehension is
by xiaq 12y ago
> There is nothing special about map and filter, they are not idiomatic Python because there are better ways to do the same things.
True, list comprehension is often used instead. But a complete typing system should be able to type-check that too. The point is not changed.
Also, I only used map and filter as an example. Python programmers tend to write a lot of generics functions without actually knowing it.
def f(g, *args):
...
r = g(*args)
...
return r
This function is actually quite generic, akin to map.
And we are not yet getting into the realm of "trait" or "concept" or "typeclass" or whatever.
def sum(*nums):
s = 0
for n in nums:
s += n
return s
Remember, although s is definitely an int, s + n may yield some completely unrelated type if n implements __radd__. The function here involves potentially infinite number of types, and their __add__ or __radd__ traits (reusing the name of the Python magic method). To fully express its type without unnecessary constraints is an interesting exercise. Since Python allows dynamic parameter list building (like sum(*nums)), dependent typing may be necessary for that purpose.
- crux 12y agoAre there languages that include the strong type checking, inference, and typeclass functionality of Haskell while also being a little more forgiving in terms of purity, so that writing ordinary programs is not quite so troublesome as in Haskell?
- habitue 12y agoRust has a decent amount of type inference, traits and strong guarantees. Ocaml/SML are both functional languages similar to haskell, and allow IO pretty much anywhere. They don't have typeclasses, (although ML people would say there's nothing you can't do with the ML module system[0]). [0]http://lambda-the-ultimate.org/node/1558 http://lambda-the-ultimate.org/node/1558
- frowaway001 12y agoScala (although it has limited type inference to require people to specify at least the inputs to methods for readability).