Hacker News new | past | comments | ask | show | jobs | submit login

Yes, you really can just tweak the parser; just (a) don't have a rule allowing comparisons to appear as children of other comparisons, and (b) add a rule that permits chains of comparisons. Types have zilch to do with this.

It's 100% a tweak to the parser.




Interestingly, you can do it with types and no parser help: https://gist.github.com/dlthomas/d18d475068f23584d473#file-c...

Obviously, that's not what's going on in Python...

It could be smoother and more generic if Haskell permitted specifying defaulting for non-numeric types. But it does support things like:

    *Main> 2 < 3 < 4 < 4 :: Bool
    False

    *Main> 2 < 3 < 4 <= 4 :: Bool
    True

    *Main> 2 <= 3 < 4 <= 4 :: Bool
    True

    *Main> 2 <= 3 > 4 <= 4 :: Bool
    False

    *Main> 2 <= 6 > 4 <= 4 :: Bool
    True


You are absolutely correct that it could be implemented as 100% a tweak to the parser.

Assuming filmor is correct, in practice as it happens to be implemented in the Python code base it is not 100% a tweak to the parser - changing the structure of the produced AST means tweaks down the line. I think the change to the parser is still the most meaningful piece, though, even there.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: