Skip to content

feat: better valcon type matching#1067

Closed
dhess wants to merge 1 commit intomainfrom
dhess/valcon-matches-type-2
Closed

feat: better valcon type matching#1067
dhess wants to merge 1 commit intomainfrom
dhess/valcon-matches-type-2

Conversation

@dhess
Copy link
Member

@dhess dhess commented Jun 10, 2023

Here we ignore the arity of the constructor and consider only the type to which the constructor belongs. This matches, e.g., both Zero and Succ i to a node whose type is Nat; whereas the previous implementation, which eta-expands the value constructor's type, would only match Zero.

However, the current implementation of this is not quite what we want, because the way I've done this, we've lost the ability to match against any polymorphic type. For example, if we have a hole of type List Int, we no longer get a match on either Cons or Nil.

I've taken this as far as I can for now due to current time constraints, so I'll mark this as a draft for now.

Here we ignore the arity of the constructor and consider only the type
to which the constructor belongs. This matches, e.g., both `Zero` and
`Succ i`` to a node whose type is `Nat`; whereas the previous
implementation, which eta-expands the value constructor's type, would
only match `Zero`.

Signed-off-by: Drew Hess <src@drewhess.com>
@dhess dhess changed the base branch from main to dhess/valcon-matches-type June 10, 2023 11:20
@dhess dhess changed the title dhess/valcon matches type 2 feat: better valcon type matching Jun 10, 2023
@dhess dhess marked this pull request as draft June 10, 2023 11:22
Base automatically changed from dhess/valcon-matches-type to main June 10, 2023 11:38
Comment on lines 588 to +598
| Just t <- exprType e -> do
pure $
vcs <&> \vc@(vc', tc, td) ->
(globalOpt' (t `eqType` valConType tc td vc') (valConName vc'), vc)
-- Here we ignore the arity of the constructor
-- and consider only the type to which the
-- constructor belongs. This matches, e.g.,
-- both @Zero@ and @Succ i@ to a node whose
-- type is @Nat@; whereas using 'valConType',
-- which eta-expands the value constructor's
-- type, would only match @Zero@.
(globalOpt' (t `eqType` mkTAppCon tc (TVar () . fst <$> astTypeDefParameters td)) (valConName vc'), vc)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can do better here. (See below)

Background: we only have regular types (i.e. not gadts), so for a type D a b with a constructor C A[a,b], we have that D S T ∋ C A[S,T] (with no restrictions on what S and T (the instantiations of the type's params) are). Thus we only need to check whether the constructor vc is a constructor of D (and that D S T is fully-applied, though this should be guarenteed by the fact that D S T is t in the code, and t = exprType e, thus of kind KType.)

Thus we need to:

  • check that t is of the form "a type constructor applied to a bunch of things"
  • extract the head D
  • check whether vc is a constructor of D

I.e. something like (off the top of my head):
Just tc == fmap fst (decomposeTAppCon t)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is implemented in #1071

@georgefst
Copy link
Contributor

Superseded by #1071.

@georgefst georgefst closed this Jun 11, 2023
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.

3 participants