diff --git a/primer/src/Primer/TypeDef.hs b/primer/src/Primer/TypeDef.hs index 00d9c2cec..ecdcf6950 100644 --- a/primer/src/Primer/TypeDef.hs +++ b/primer/src/Primer/TypeDef.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE OverloadedLabels #-} - module Primer.TypeDef ( TypeDef (..), ValCon (..), @@ -19,7 +17,9 @@ import Foreword import Control.Monad.Fresh (MonadFresh) import Data.Data (Data) -import Optics (Field2 (_2), mapped, over, traverseOf, traversed, (%)) +import Data.Generics.Product (HasParam (param), Param (StarParam)) +import Optics (set, traverseOf) +import Primer.Core.DSL.Meta (kmeta, meta) import Primer.Core.Meta ( ID, TyConName, @@ -33,7 +33,7 @@ import Primer.Core.Type ( Type' (TForall, TFun, TVar), TypeMeta, ) -import Primer.Core.Utils (forgetKindMetadata, forgetTypeMetadata, generateKindIDs, generateTypeIDs) +import Primer.Core.Utils (forgetTypeMetadata) import Primer.JSON ( CustomJSON (CustomJSON), FromJSON, @@ -105,24 +105,12 @@ typeDefAST = \case typeDefKind :: TypeDef b () -> Kind' () typeDefKind = foldr (KFun () . snd) (KType ()) . typeDefParameters --- TODO/REVIEW: I cannot see how to do this nice and lens-y (see old code --- above) because we cannot change metadata in params indep to in ctors, --- as both controlled by same `c` forgetTypeDefMetadata :: TypeDef b c -> TypeDef () () -forgetTypeDefMetadata (TypeDefPrim td) = TypeDefPrim $ over (#primTypeDefParameters % mapped % _2) forgetKindMetadata td -forgetTypeDefMetadata (TypeDefAST (ASTTypeDef ps cs hs)) = - TypeDefAST $ - ASTTypeDef - (over (mapped % _2) forgetKindMetadata ps) - (over (mapped % #valConArgs % mapped) forgetTypeMetadata cs) - hs +forgetTypeDefMetadata = + set (param @1) () + . set (param @0) () generateTypeDefIDs :: MonadFresh ID m => TypeDef () () -> m (TypeDef TypeMeta KindMeta) -generateTypeDefIDs (TypeDefPrim td) = TypeDefPrim <$> traverseOf (#primTypeDefParameters % traversed % _2) generateKindIDs td -generateTypeDefIDs (TypeDefAST (ASTTypeDef ps cs hs)) = - TypeDefAST - <$> liftA3 - ASTTypeDef - (traverseOf (traversed % _2) generateKindIDs ps) - (traverseOf (traversed % #valConArgs % traversed) generateTypeIDs cs) - (pure hs) +generateTypeDefIDs = + traverseOf (param @1) (\() -> meta) + <=< traverseOf (param @0) (\() -> kmeta)