Pattern Signatures: what can scoped type variables refer to?
Anthony Clayden <[email protected]> Thu, 6 Dec 2018 23:15:37 +1300
| Newsgroups | gmane.comp.lang.haskell.hugs.user |
|---|---|
| Message-ID | <CAM7nRYR4Vxs8tkVNmSVq5YP45HkBfjmUYKRL1Y+HzXYTHUbL0Q@mail.gmail.com> |
--===============3380936072808360671== Content-Type: multipart/alternative; boundary="00000000000058baea057c57c85d" --00000000000058baea057c57c85d Content-Type: text/plain; charset="UTF-8" HugsMode supports signatures in patterns, roughly equivalent to the (now deprecated) `PatternSignatures` GHC extension. Hugs doesn't support GHC's full `ScopedTypeVariables` functionality with the daft/bogus `forall` quantification on stand-alone signatures -- which IMO is a wart. I'm reading the 2018 paper 'Type variables in patterns' Eisenberg/Breitner/Peyton Jones, section 3.1, 3.5 "a scoped type variable may refer only to another type variable". Hugs applies the same rule. I'm persuaded by section 3.5's saying that seems an arbitrary and unnecessary restriction. "We therefore propose to simply drop this restriction." This is github PR #128 in GHC. Done in Hugs: I've just suppressed the error message, is in one validation routine in one module. So this example compiles > prefix :: Int -> [[Int]] -> [[Int]] > prefix (x :: b) yss = map xcons yss -- previously :: b was rejected > where xcons ys = x : ys :: [b] -- now can use b to annotate the rhs It seems to me that inline tyvar bindings/annotations like this is preferable to the `ScopedTypeVariables` explicit `foralls` on a standalone signature signalling some tyvar is being scoped over some declaration/term. See also similar comments in github PR #119 'Resurrect PatternSignatures' (now withdrawn). There were quite a few opinions to the effect that `PatternSignatures` (but not full bore `ScopedTypeVariables`) should always have been part of Haskell; and perhaps that'd be ripe for inclusion in Haskell 2010. AntC --00000000000058baea057c57c85d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto">HugsMode supports signatures in patterns, roughly equival= ent to the (now deprecated) `PatternSignatures` GHC extension. Hugs doesn&#= 39;t support GHC's full `ScopedTypeVariables` functionality with the da= ft/bogus `forall` quantification on stand-alone signatures -- which IMO is = a wart.</div><div dir=3D"auto"><br></div><div dir=3D"auto">I'm reading = the 2018 paper 'Type variables in patterns' Eisenberg/Breitner/Peyt= on Jones, section 3.1, 3.5 "a scoped type variable may refer only to a= nother type variable". Hugs applies the same rule.</div><div dir=3D"au= to"><br></div><div dir=3D"auto">I'm persuaded by section 3.5's sayi= ng that seems an arbitrary and unnecessary restriction. "We therefore = propose to simply drop this restriction." This is github PR #128 in GH= C.</div><div dir=3D"auto"><br></div><div dir=3D"auto">Done in Hugs: I'v= e just suppressed the error message, is in one validation routine in one mo= dule.</div><div dir=3D"auto"><br></div><div dir=3D"auto">So this example co= mpiles</div><div dir=3D"auto"><br></div><div dir=3D"auto">> prefix :: In= t -> [[Int]] -> [[Int]]</div><div dir=3D"auto">> prefix (x :: b) y= ss =3D map xcons yss =C2=A0 =C2=A0 =C2=A0 =C2=A0 -- previously :: b was rej= ected</div><div dir=3D"auto">> =C2=A0 where xcons ys =3D x : ys :: [b] = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-- now can use b to = annotate the rhs</div><div dir=3D"auto"><br></div><div dir=3D"auto">It seem= s to me that inline tyvar bindings/annotations like this is preferable to t= he `ScopedTypeVariables` explicit `foralls` on a standalone signature signa= lling some tyvar is being scoped over some declaration/term. See also simil= ar comments in github PR =C2=A0#119 'Resurrect PatternSignatures' (= now withdrawn). There were quite a few opinions to the effect that `Pattern= Signatures` (but not full bore `ScopedTypeVariables`) should always have be= en part of Haskell; and perhaps that'd be ripe for inclusion in Haskell= 2010.</div><div dir=3D"auto"><br></div><div dir=3D"auto">AntC</div> --00000000000058baea057c57c85d-- --===============3380936072808360671== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KSHVncy1Vc2Vy cyBtYWlsaW5nIGxpc3QKSHVncy1Vc2Vyc0BoYXNrZWxsLm9yZwpodHRwOi8vbWFpbC5oYXNrZWxs Lm9yZy9jZ2ktYmluL21haWxtYW4vbGlzdGluZm8vaHVncy11c2Vycwo= --===============3380936072808360671==--