Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions primer/src/Primer/Action/Available.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ import Primer.Core (
_type,
_typeMetaLens,
)
import Primer.Core.Transform (
mkTAppCon,
)
import Primer.Core.Utils (forgetTypeMetadata, freeVars)
import Primer.Def (
ASTDef (..),
Expand All @@ -104,7 +107,6 @@ import Primer.TypeDef (
TypeDefMap,
ValCon (valConArgs),
valConName,
valConType,
)
import Primer.Typecheck (
Cxt,
Expand Down Expand Up @@ -586,7 +588,14 @@ options typeDefs defs cxt level def0 sel0 = \case
| 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)
Comment on lines 588 to +598

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.

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
Copy Markdown
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

_ ->
pure $ vcs <&> \vc@(vc', _, _) -> (globalOpt . valConName $ vc', vc)
exprType e = e ^? _exprMetaLens % _type % _Just % (_chkedAt `afailing` _synthed)
Expand Down