# An alternative frontend for Haskell?

**URL:** <https://discourse.haskell.org/t/an-alternative-frontend-for-haskell/7793>\
**Category:** Links\
**Created:** [October 5, 2023, 6:20am UTC](https://discourse.haskell.org/t/an-alternative-frontend-for-haskell/7793 "2023-10-05T06:20:09Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![AntC2](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/antc2/32/1872_2.png) [@AntC2](https://discourse.haskell.org/u/AntC2)\
**Post date:** [October 7, 2023, 10:20pm UTC](https://discourse.haskell.org/t/an-alternative-frontend-for-haskell/7793/23 "2023-10-07T22:20:48Z")

</div>

> [@atravers](#):
>
> > remove […] partial functions like `head` […]
> 
> …and `(/)`, `div`, `mod`, `divMod`, `quot`, `rem`, `quotRem`, _et al!_

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

> [@george.fst](#):
>
> This is really not that different to what I’d do in Haskell:
> 
> ```haskell
> f = \case
> Nil -> _
> Node{value} -> _
> 
> ```

> [@gilmi](#):
>
> Btw you can still do the thing you wanted to do in Haskell with similar convenience and without field selectors by using aliasing:
> 
> ```haskell
> incTree = \case
> Nil -> Nil
> n@Node{value} -> n { value = value + 1 }
> 
> ```

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.

> [@jameshaydon](#):
>
> ```haskell
> updateCounts i acc = if isEven i
> then acc {evens = acc.evens + 1}
> else acc {odds = acc.odds + 1}
> 
> ```
> 
> (This is working Purescript code.)  
> Note that I don’t need to declare the record type anywhere, this code just works standalone. This is what I understand by _anonymous_ (unnamed, undeclared) records.

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.

```haskell
    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?

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

```

---

<div class="post-metadata">

**Author:** ![AntC2](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/antc2/32/1872_2.png) [@AntC2](https://discourse.haskell.org/u/AntC2)\
**Post date:** [October 9, 2023, 10:58am UTC](https://discourse.haskell.org/t/an-alternative-frontend-for-haskell/7793/24 "2023-10-09T10:58:22Z")

</div>

> [@gilmi](#):
>
> being able to write `let x = Nil in x { value = 1 }` and `value Nil`

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

```haskell
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.

---

<div class="post-metadata">

**Author:** ![AntC2](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/antc2/32/1872_2.png) [@AntC2](https://discourse.haskell.org/u/AntC2)\
**Post date:** [October 26, 2023, 11:43pm UTC](https://discourse.haskell.org/t/an-alternative-frontend-for-haskell/7793/25 "2023-10-26T23:43:13Z")

</div>

> [@gilmi](#):
>
> In a language with first class records like PureScript, field selector like the ones in Haskell are irrelevant because they don’t work on the data type `Tree`, they work on the payload of `Node`. So your snippet becomes:
> 
> ```haskell
> incTree = case _ of
> Nil -> Nil
> Node r ->
> Node (r { value = r.value + 1 })
> 
> ```

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

```haskell
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.

---

<div class="post-metadata">

**Author:** ![atravers](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@atravers](https://discourse.haskell.org/u/atravers)\
**Post date:** [October 31, 2023, 10:23am UTC](https://discourse.haskell.org/t/an-alternative-frontend-for-haskell/7793/26 "2023-10-31T10:23:38Z")

</div>

> [@](#):
>
> remove […] partial functions like `head` […]

…and at [2022 Nov 16](https://github.com/haskell/core-libraries-committee/issues/87#issuecomment-1315926944), the [canonical precedent](https://github.com/haskell/core-libraries-committee/issues/87) 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.

[Previous page](https://discourse.haskell.org/t/an-alternative-frontend-for-haskell/7793.md?page=1)
