Skip to content

Disallow Coercible instance declarations#3905

Merged
hdgarrood merged 1 commit intopurescript:masterfrom
kl0tl:disallow-coercible-instance-declarations
Aug 30, 2020
Merged

Disallow Coercible instance declarations#3905
hdgarrood merged 1 commit intopurescript:masterfrom
kl0tl:disallow-coercible-instance-declarations

Conversation

@kl0tl
Copy link
Copy Markdown
Member

@kl0tl kl0tl commented Jul 6, 2020

GHC rejects the following exemple with an explicit error:

module Example where

import Data.Coerce (Coercible)

data D

instance Coercible D D
Example.hs:7:10: error:
    • Illegal instance declaration for ‘Coercible D D’
        Manual instances of this class are not permitted.
    • In the instance declaration for ‘Coercible D D’
  |
7 | instance Coercible D D
  |          ^^^^^^^^^^^^^

We don‘t accept such declaration either but the error message is less helpful:

module Example where

import Prim.Coerce (class Coercible)

data D

instance coercible :: Coercible D D
Error found:
in module Example
at Example.purs:7:1 - 7:36 (line 7, column 1 - line 7, column 36)

  Could not match type
          
    Record
          
  with type
                    
    Coercible$Dict D
                    

while trying to match type Record (() @Type)
  with type Coercible$Dict D D
while checking that expression Coercible {}
  has type Coercible$Dict D D
in value declaration coercible

See https://github.com/purescript/documentation/blob/master/errors/TypesDoNotUnify.md for more information,
or to contribute content related to this error.

Copy link
Copy Markdown
Contributor

@hdgarrood hdgarrood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

@hdgarrood hdgarrood merged commit ac2def0 into purescript:master Aug 30, 2020
@kl0tl kl0tl deleted the disallow-coercible-instance-declarations branch September 18, 2020 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants