Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate the 'no change' parts of AST traversals somehow #26

Open
andy-morris opened this issue Jun 15, 2020 · 1 comment
Open

Generate the 'no change' parts of AST traversals somehow #26

andy-morris opened this issue Jun 15, 2020 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@andy-morris
Copy link
Contributor

andy-morris commented Jun 15, 2020

NB the traversal needs to be applicative not just pure

@andy-morris andy-morris added this to the milestone Jun 15, 2020
@andy-morris
Copy link
Contributor Author

andy-morris commented Jul 22, 2020

data TransformationParts =
  TransformationParts {
    partTerm :: ExpQ,
    ...
  }

defaultTransformationParts = TransformationParts {partTerm = [|\case {}|], ...}

data Transformations ext1 ext2 f =
  Transformations {
    transformTerm :: forall primTy primVal. Term' ext1 primTy primVal -> f (Term' ext2 primTy primVal),
    ...
  }

makeTransformTerm :: ExpQ -> ExpQ -> ExpQ
makeTransformTerm self lam = do
  defaults <- ...
    -- e.g. match [p|Lam t|] (normalB [|Lam <$> transformTerm t|]) []
  LamCaseE matches <- lam
  pure $ LamCaseE $ matches ++ filter (not mentioned in matches) defaults

makeTransformations :: TransformationParts -> ExpQ
makeTransformations (TransformationParts {..}) =
  [|
    fix \self -> Transformations {
      transformTerm = $(makeTransformTerm [|self|] partTerm),
      ...
    }
  |]

------

module Juvix.Core.IR.Unify where

import qualified Juvix.Core.IR.Types as IR
import qualified Juvix.Core.IR.Types.Base as IR

data T deriving Data

-- TODO also abbreviate this bit obviously
IR.extendTerm  "Term"  [] [t|T|] \_ _ -> IR.defaultExtTerm
IR.extendElim  "Elim"  [] [t|T|] \_ _ -> IR.defaultExtElim
IR.extendValue "Value" [] [t|T|] \_ _ ->
  IR.defaultExtValue {
    IR.typeValueX = [("VMetaVar", [[t|MetaVar|]])]
  }
IR.extendNeutral "Neutral" [] [t|T|] \_ _ -> IR.defaultExtNeutral
-- etc etc

toValue   :: Value primTy primVal   -> Maybe (IR.Value primTy primVal)
toNeutral :: Neutral primTy primVal -> Maybe (IR.Neutral primTy primVal)
Transformations {transformValue   = toValue,
                 transformNeutral = toNeutral, {- ... -} } =
  $(IR.makeTransformations $
    IR.defaultTransformationParts {
      IR.transformValue = [|\case
          VMetaVar α -> Nothing
        |]
    }
  )

@andy-morris andy-morris added the enhancement New feature or request label Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant