News for hackers. Stuff that matters.
Re:Lisp and Haskell (2015) by tome on Thursday October 08, 2020 @06:40AM (#24717838)
The Foldable instance for Maybe is one of the biggest warts in Haskell. It's not limited to Haskell, by the way.

    def getUsers(f):
        return (logged_in_users(f), logged_out_users(f))

    def userCount(f):
        return len(getUsers(f))
Re:Lisp and Haskell (2015) by q3k on Thursday October 08, 2020 @06:43AM (#24717848)
Sure, but Python and Python developers don’t hype up its type system to be the solution to all your programming woes :).
Re:Lisp and Haskell (2015) by tome on Thursday October 08, 2020 @07:07AM (#24717962)
I'm not sure what "Haskell developers" are saying, but this Haskell developer says "Haskell provides many tools that can be used to solve programming woes. One such tool is its strong and flexible types system (there are several other tools, such as immutability, functional style)."
Re:Lisp and Haskell (2015) by Kednicma on Thursday October 08, 2020 @10:32AM (#24719384)
And Python provides readable syntax. Your example has an easy-to-spot bug, just from reading the code and knowing Python's semantics. Haskell's "programmable semicolon" ends up being a problem here because, thanks to typeclasses, the programmer usually does not know which semicolon they are programming under!

"Python provides many tools that can be used to solve programming woes. One such tool is its strong and readable syntax." Do you see how empty this sort of platitude is?

Re:Lisp and Haskell (2015) by gtf21 on Thursday October 08, 2020 @10:54AM (#24719620)
I don't think that illustrates that promotion of the type system as a useful tool is an "empty platitude". A well constructed syntax is certainly a nice feature of a programming language. One might say a language like brainfuck does not have a syntax which makes the code easily readable, and therefore is the worse for it.

Similarly, one might say that a strong type system is a useful tool. That doesn't make it a panacea (and I don't think that this was the claim), but that doesn't mean one can't appreciate it as a good tool.

Re:Lisp and Haskell (2015) by ghostwriter on Thursday October 08, 2020 @11:30AM (#24720052)
The problem with this comparison is that readable syntax is a subjective notion, whereas type system is an objective thing that can be evaluated based on its strictly defined boundaries - it's either possible or impossible to encode all required software specification with a provided type system, and if something is not possible, we know exactly what are these things that don't fit into the type system, and therefore we cannot rely on the compiler to prove their correctness.
Re:Lisp and Haskell (2015) by wk_end on Thursday October 08, 2020 @01:16PM (#24721362)
Er, the difference here is that we're given the Python code for `getUsers` but not the Haskell code for it. That makes the error in Python obvious. The incorrect `userCount` in Python looks just as obviously correct as the incorrect `userCount` in Haskell; and conversely, if we were given the code for the Haskell `getUsers` (or even just the type signature!) the error would be just as easy to spot.
Re:Lisp and Haskell (2015) by tome on Thursday October 08, 2020 @10:37AM (#24719438)
I didn't intend to make this into a competition between Haskell and Python.
Re:Lisp and Haskell (2015) by vindarel on Thursday October 08, 2020 @06:51PM (#24724789)
That's why Lisp has multiple return values, which are different from returning a tuple. It's great for refactoring. (https://lispcookbook.github.io/cl-cookbook/functions.html#mu...)
Re:Lisp and Haskell (2015) by 4WIW on Thursday October 08, 2020 @11:18AM (#24719884)
To make this code clearer:

    def get_users(f) -> Tuple[List, List]:
       return (logged_in_users(f), logged_out_users(f))

    def user_count(f) -> int:
       return len(get_users())
Now it's clear this is just wrong code. To fix it:

    def get_users(f) -> List:
       return logged_in_users(f) + logged_out_users(f)

    def user_count(f) -> int:
       return len(get_users())
Re:Lisp and Haskell (2015) by wk_end on Thursday October 08, 2020 @01:13PM (#24721316)
That doesn't really "fix it". Even assuming there are no other callers of `get_users` that you might be breaking here (possibly silently, since lists and tuples in Python have overlapping interfaces), you're making `get_users` less useful by dropping structure that at least someone, at some point, thought was useful.

Also, you should annotate the type of your lists :)

  def get_users(f) -> Tuple[List[User], List[User]]:
    return (logged_in_users(f), logged_out_users(f))

  def user_count(f) -> int:
    logged_in_users, logged_out_users = get_users()
    return len(logged_in_users) + len(logged_out_users)