[ghc-steering-committee] #409: Exportable named defaults, Recommendation: Partial Accept

Eric Seidel eric at seidel.io
Thu Jun 17 02:12:52 UTC 2021


On Fri, Jun 11, 2021, at 06:14, Spiwack, Arnaud wrote:
>  * I’m rather unsure what to think about regarding the non-total 
> priority (the fact that you can have `default C (A, B); default D (B, 
> A)` and need to default a variable `x` with `(C x, D x)`). This sounds 
> like something that must at least be specified. Am I correct that it 
> isn’t?

It is specified to be a static error, and the solution is either

- define your own, consistent default rules for C and D in the current module, OR
- ascribe types to the ambiguous use-sites and bypass default resolution entirely.

See sections [2.5] and [5.1] in the proposal.

It's a bit of a sharp edge, to be sure. But defaulting rules are anti-modular much like type classes, and I think this is the most sensible thing to do here.

[2.5]: https://github.com/blamario/ghc-proposals/blob/exportable-named-default/proposals/0000-exportable-named-default.rst#25rules-for-disambiguation-at-the-use-site
[5.1]: https://github.com/blamario/ghc-proposals/blob/exportable-named-default/proposals/0000-exportable-named-default.rst#51use-site-conflicts

>  * Regarding imports: in a first approximation explicit imports are 
> useless. Having implicit imports lets me, for instance, define `default 
> IsList ([])` in the prelude, and then turn `OverloadedList` on in 
> `GHC2023` and not break existing programs. 

There's a bit of a subtlety here in the use of "explicit" vs "implicit", and I'm not sure how you're using them here.

We have at least three proposals for the behavior of imports. Given

```
module Defaults where
default IsString (Text)
```

(A) Fully implicit (like class instances)

```
import Defaults  -- imports `default IsString (Text)`
import Defaults ()  -- imports `default IsString (Text)`
```

(B) Fully explicit (Richard's preference, I believe)

```
import Defaults  -- does not import `default IsString (Text)`
import Defaults ()  -- does not import `default IsString (Text)`
import Defaults (default IsString) -- imports `default IsString (Text)`
```

(C) Like normal values

```
import Defaults  -- imports `default IsString (Text)`
import Defaults ()  -- does not import `default IsString (Text)`
import Defaults (default IsString) -- imports `default IsString (Text)`
```

Since the Prelude is implicitly imported without an import list, both A and C would let you avoid an extra import. Same goes for Prelude replacements.

Eric


More information about the ghc-steering-committee mailing list