Skip to content

Make Expr's role nominal - #416

Merged
TeofilC merged 1 commit into
masterfrom
wip/expr-role
Sep 22, 2026
Merged

TeofilC merged 1 commit into
masterfrom
wip/expr-role

Conversation

@TeofilC

@TeofilC TeofilC commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Previously Expr was inferred to have a phantom role, which meant that we could coerce :: Expr a -> Expr b for any a and b.

We set it to nominal, which means we can only do coerce :: a ~ b => Expr a -> Expr b.

We could have also done representational which would have additionally allowed coercing between types with the same representation, ie, if they had a Coercible instance themselves. This isn't correct since types with the same representation could have different DBType/Serializable instances, which would lead to bugs.

Credit goes to @raehik for noticing this.

@ocharles ocharles left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Impressed I missed this! In earlier versions of Rel8 I always remembered it, but forgot it for the most important version 😄

@TeofilC
TeofilC enabled auto-merge (squash) September 22, 2026 10:30
Previously Expr was inferred to have a phantom role, which meant that we
could `coerce :: Expr a -> Expr b` for any `a` and `b`.

We set it to nominal, which means we can only do `coerce :: a ~ b =>
Expr a -> Expr b`.

We could have also done representational which would have additionally
allowed coercing between types with the same representation, ie, if they
had a Coercible instance themselves. This isn't correct since types with
the same representation could have different DBType/Serializable
instances, which would lead to bugs.
@TeofilC
TeofilC merged commit e5cc70b into master Sep 22, 2026
3 checks passed
@TeofilC
TeofilC deleted the wip/expr-role branch September 22, 2026 11:01
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