From anthony_clayden at clear.net.nz Thu Dec 6 10:15:37 2018 From: anthony_clayden at clear.net.nz (Anthony Clayden) Date: Thu, 6 Dec 2018 23:15:37 +1300 Subject: [Hugs-users] Pattern Signatures: what can scoped type variables refer to? Message-ID: 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony_clayden at clear.net.nz Thu Dec 6 10:38:16 2018 From: anthony_clayden at clear.net.nz (Anthony Clayden) Date: Thu, 6 Dec 2018 23:38:16 +1300 Subject: [Hugs-users] Explain typeclass instance resolution Message-ID: He he, while I was poking about in the type inference code ... There's an experimental command `:xplain` instance resolution. The code to implement it needs switching on with a preprocessor flag set in options.h.in then ./configure and recompile Hugs. Use it by giving a constraint to be explained: Hugs> :x Show (Maybe [Int]) (It seems a bit temperamental, fair enough for a hidden feature: if it can't resolve an instance, it'll say so, but also give some misleading messages with fragments of code leftover from previous uses.) AntC -------------- next part -------------- An HTML attachment was scrubbed... URL: