Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> This module doesn't seem to make it possible to type-annotate map and filter, which are Python builtins.

In Haskell map is

    map :: (a->b) -> [a] -> [b]
How could we do something like that in a Python type extension? One way would be to just use the Haskell notation in quotes:

    @type("(a->b) -> [a] -> [b]")
    def myMap(fn, as):
        #...etc...
An alternative would be to define a function Fun for describing functional types, and gen.{something} for a generic type, e.g.:

    @type(Fun(gen.a, gen.b), [gen.a], ret=[gen.b])
    def myMap ...etc...
But that notation doesn't (at least to me) look as clean as the Haskell.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: