News for hackers. Stuff that matters.
Re:Grain: A strongly-typed functional programming language f... by masklinn on Tuesday July 31, 2018 @10:51AM (#17653619)
> Errors could presumably be provided as return values (similar to Rust's Option or Haskell's Either), though we know from languages like Go that propagating these manually is a chore and an eyesore.

Mostly because Go is terrible.

> Haskell's type system is extremely powerful, but it cannot catch this at compile time.

The problem is not the type system, it's that Haskell's error handling is inconsistent.

Elm, despite having a much simpler type system than Haskell, handles this properly:

    head : List a -> Maybe a
This has nothing to do with the type system itself and everything to do with how the type system is used (or not used). The designers of Haskell's `head` decided to make it a partial function, leading to type-checking inputs not generating any output.
Re:Grain: A strongly-typed functional programming language f... by galaxyLogic on Tuesday July 31, 2018 @11:07AM (#17653740)
This seems like such an obvious solution it makes me wonder why creators of Haskell did not think of it? Lists are a very basic type used all the time if you don't get that right lot of the value of the great type-system is lost I would think.
Re:Grain: A strongly-typed functional programming language f... by lodi on Tuesday July 31, 2018 @12:37PM (#17654620)
They did. The elm-style version is in the standard libraries as:

    listToMaybe :: [a] -> Maybe a
(http://hackage.haskell.org/package/base-4.11.1.0/docs/Data-M...)
Re:Grain: A strongly-typed functional programming language f... by galaxyLogic on Tuesday July 31, 2018 @11:23PM (#17659405)
That's a lengthy name for the simple operation of getting the first element of a list if there is one. I would have preferred 'car' :-)
Re:Grain: A strongly-typed functional programming language f... by lodi on Friday August 03, 2018 @11:42AM (#17680761)
It's a bit verbose, but this kind of thing is far less prevalent in Haskell anyway; most of the time you destructure a list through pattern matching, not explicit head/tail functions.
Re:Grain: A strongly-typed functional programming language f... by masklinn on Tuesday July 31, 2018 @11:17AM (#17653844)
I think it's because they weren't very clear on how they wanted to handle partial functions / error reporting, and historically functions like head are partial.

Making them total makes them a bit heavier for the best case, and furthermore can seem unnecessary (as you could just pattern-match the list itself).

You can also see this oddity in Haskell allowing non-exhaustive case, and allowing refutable patterns in bindings.