Field names starting Upper [Was: [haskell-cafe/ghc-proposals] Allow reserved identifiers as fields ...
Anthony Clayden <[email protected]> Mon, 30 Dec 2024 13:57:52 +1300
| Newsgroups | gmane.comp.lang.haskell.hugs.user |
|---|---|
| Message-ID | <CABU_mxhibj8=jt3cR6yF9UFPCmmsGh=vK1fnB_v6bstrRQi=Hw@mail.gmail.com> |
--===============4047282697015907696== Content-Type: multipart/alternative; boundary="000000000000f761f4062a724db1" --000000000000f761f4062a724db1 Content-Type: text/plain; charset="UTF-8" I said ( https://mail.haskell.org/pipermail/haskell-cafe/2024-December/136986.html) On Wed, 25 Dec 2024 at 16:49, Anthony Clayden <[email protected]> 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.) --000000000000f761f4062a724db1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>I said (<a href=3D"https://mail.haskell.org/pipermail= /haskell-cafe/2024-December/136986.html">https://mail.haskell.org/pipermail= /haskell-cafe/2024-December/136986.html</a>)</div><br><div class=3D"gmail_q= uote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, 2= 5 Dec 2024 at 16:49, Anthony Clayden <<a href=3D"mailto:anthony.d.clayde= [email protected]">[email protected]</a>> wrote:<br></div><blockquot= e class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px s= olid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div>...</div><div= ><br></div><div><div>[**] I'm particularly keen on field names starting= upper case, because they're injective/part of the structure, like data= constructors.</div><div><br></div><div><br></div></div></div></blockquote>= <div><br></div><div>And previously with Hugs (<a href=3D"https://mail.haske= ll.org/pipermail/hugs-users/2020-May/000927.html">https://mail.haskell.org/= pipermail/hugs-users/2020-May/000927.html</a>)</div><div><br></div><blockqu= ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px= solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div><div><br cl= ass=3D"gmail-Apple-interchange-newline"><span style=3D"color:rgb(0,0,0);whi= te-space:pre-wrap">* I've taught Trex to support field labels starting = upper-case, because,</span></div></div></div></blockquote><div><blockquote = class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px sol= id rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div><div><span styl= e=3D"color:rgb(0,0,0);white-space:pre-wrap"> well for me they're more = like constructors than variables.</span><br class=3D"gmail-Apple-interchang= e-newline"><br></div></div></div></blockquote><div><br></div></div><div><br= ></div><div>So can I combine that work? Yes, providing I use Upper-case lab= els only within `{ ... }`. These can combine lower with Upper field names w= ithin the same data type; can pun on the lower.</div><div><br></div><div>&g= t;</div><div>>=C2=A0 =C2=A0 =C2=A0data Upup a =3D MkUp{ down :: a, Up ::= Int } =C2=A0 deriving (Eq, Show)</div><div>></div><div>>=C2=A0 =C2= =A0 =C2=A0anUp =C2=A0=3D MkUp{ down =3D 'a', Up =3D 5 }=C2=A0 =C2= =A0 =C2=A0 -- build</div>>=C2=A0 =C2=A0 =C2=A0recUp =3D anUp{ Up =3D 7 }= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-- field update by Up labe= l, record syntax</div><div class=3D"gmail_quote gmail_quote_container">>= </div><div class=3D"gmail_quote gmail_quote_container">>=C2=A0=C2=A0 =C2= =A0 succUp (MkUp {down, Up =3D u} ) =3D MkUp{ down =3D succ down, Up =3D su= cc u }<br><div>></div><div><br></div><div>You can't use a field sele= ction function: 'ERROR - "Up" is not a data constructor'.= </div><div>(It looks like Hugs does generate such a function; this error is= a syntax rejection in trying to use it.)</div><div><br></div><div><br></di= v></div></div> --000000000000f761f4062a724db1-- --===============4047282697015907696== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KSHVncy1Vc2Vy cyBtYWlsaW5nIGxpc3QKSHVncy1Vc2Vyc0BoYXNrZWxsLm9yZwpodHRwOi8vbWFpbC5oYXNrZWxs Lm9yZy9jZ2ktYmluL21haWxtYW4vbGlzdGluZm8vaHVncy11c2Vycwo= --===============4047282697015907696==--