[Hugs-users] Field names starting Upper [Was: [haskell-cafe/ghc-proposals] Allow reserved identifiers as fields ...
Anthony Clayden
anthony.d.clayden at gmail.com
Mon Dec 30 00:57:52 UTC 2024
I said (
https://mail.haskell.org/pipermail/haskell-cafe/2024-December/136986.html)
On Wed, 25 Dec 2024 at 16:49, Anthony Clayden <anthony.d.clayden at gmail.com>
wrote:
> ...
>
> [**] I'm particularly keen on field names starting upper case, because
> they're injective/part of the structure, like data constructors.
>
>
>
And previously with Hugs (
https://mail.haskell.org/pipermail/hugs-users/2020-May/000927.html)
> * I've taught Trex to support field labels starting upper-case, because,
>
well for me they're more like constructors than variables.
>
>
So can I combine that work? Yes, providing I use Upper-case labels only
within `{ ... }`. These can combine lower with Upper field names within the
same data type; can pun on the lower.
>
> data Upup a = MkUp{ down :: a, Up :: Int } deriving (Eq, Show)
>
> anUp = MkUp{ down = 'a', Up = 5 } -- build
> recUp = anUp{ Up = 7 } -- field update by Up label,
record syntax
>
> succUp (MkUp {down, Up = u} ) = MkUp{ down = succ down, Up = succ u }
>
You can't use a field selection function: 'ERROR - "Up" is not a data
constructor'.
(It looks like Hugs does generate such a function; this error is a syntax
rejection in trying to use it.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/hugs-users/attachments/20241230/68e911bc/attachment.html>
More information about the Hugs-Users
mailing list