An alternative frontend for Haskell?

I like a lot of these ideas in a vacuum, but I don’t think they’re worth the fragmentation. It also becomes a bit too kitchen sink further down. Eg polymorphic variants seems like a pretty significant change. It would have massive divergent effects on the ecosystem and interop with regular haskell.

…how on this planet did I forget this?


While not “Haskell with an alternative syntax”, these could also be informative…and they appeared in my search:

2 Likes

… and (+), (-), (*) for fixed-width numeric types, because they can cause over/underflow without even giving a run-time exception.

In view of the risk of partialness for field selector functions/if we’re only ever going to pattern match for label bindings [**], I’d like to allow labels spelled upper-case. To me they’re more like (de-)constructors, not functions.

[**] Or if we’re going to use specific syntax Node.Value for field access.

Yeah even with my Haskell-ish eyes, that update syntax looks misleading: I have to do a double-take that’s not function acc applied to some record.

    updateCounts i {Evens = evens, Odds = odds} = if isEven i
      then {Evens = evens + 1, Odds = odds}
      else {Evens = evens,     Odds = odds + 1}

Any more readable? (It’s just making explicit what the code will compile to anyway.) Or?

    updateCounts i {Evens = evens | r} | isEven i = {Evens = evens + 1 | r}
    updateCounts i {Odds = odds   | r}            = {Odds = odds + 1   | r}
1 Like

I’m not seeing anything specific to Haskell records/field selectors:

let y = Nothing in fromJust y

let z = [] in head z

Of course real-life examples are going to be more convoluted than that. The coverage checker will detect the ‘obvious’ ones.

remove footguns such as partial functions like head

Fast as you remove them, people are going to write their own. And uses of head might be perfectly safe – it’s just the coverage checker can’t see through the program logic.

You can get that code accepted in Haskell today (or even in H98 except for the r.value: use value r instead). You need

data Tree a
      = Nil
      | Node (Node' a)
data Node' a = MkNode{ value :: a, left :: Tree a, right :: Tree a }

IOW, just as with purescript, nest an extra constructor to express the field names. You might even be able to use the auxiliary Node' within other data types; in effect re-using the field names.

So your ‘Alternative front end’ could support some syntactic sugar to make those decls less verbose.

There are good reasons to introduce free-standing first-class records/global field labels into a Haskell, but merely to avoid partial access is not one of them: I suspect the nested-constructor here will be just annoying enough people will define direct extractor functions – and you’re back to partiality.

…and at 2022 Nov 16, the canonical precedent was set for all future decisions regarding partiality in Haskell. Now the wait begins for “the other shoe to drop” - the first of the proposals to remove them altogether from the current front-section.