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

The point is that the Haskell type system is an expressive way of solving systematic bugs. You can express both the data itself and the valid ways of handling it using types, which gives you a space to design yourself out of systemic problems. And when something goes awry, the strict typing and control over side effects means that you can refactor fearlessly!

Re. the example, the compiler can infer types, and you can write almost the exact same code in Haskell as in Python:

    doSomething = do
       let result = getResult
       when (result /= "a result")
            (throwError $ InvalidResultError result)
       return 42
But as it has been noted, you are unlikely to find code like this in Haskell. An element of Either type at the top level, without arguments is either always going to be Left or always going to be Right, so it is a bit pointless. Since this example is so abstract it is hard to see what the idiomatic Haskell would be, because it would depend on the particulars.


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

Search: