1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 04:43:18 +03:00

[concrete] rename DataType to Inductive

This commit is contained in:
Jan Mas Rovira 2022-01-21 13:12:25 +01:00
parent 8c31d7097d
commit d6b616bdd9
4 changed files with 84 additions and 84 deletions

View File

@ -35,11 +35,11 @@ type family NameType (s :: Stage) :: (res :: GHC.Type) | res -> s where
NameType 'Scoped = S.Name NameType 'Scoped = S.Name
type family ExpressionType (s :: Stage) :: GHC.Type where type family ExpressionType (s :: Stage) :: GHC.Type where
ExpressionType 'Parsed = (ExpressionAtoms 'Parsed) ExpressionType 'Parsed = ExpressionAtoms 'Parsed
ExpressionType 'Scoped = Expression ExpressionType 'Scoped = Expression
type family PatternType (s :: Stage) :: GHC.Type where type family PatternType (s :: Stage) :: GHC.Type where
PatternType 'Parsed = (PatternAtom 'Parsed) PatternType 'Parsed = PatternAtom 'Parsed
PatternType 'Scoped = Pattern PatternType 'Scoped = Pattern
type family ImportType (s :: Stage) :: GHC.Type where type family ImportType (s :: Stage) :: GHC.Type where
@ -62,7 +62,7 @@ data Statement (s :: Stage)
= StatementOperator OperatorSyntaxDef = StatementOperator OperatorSyntaxDef
| StatementTypeSignature (TypeSignature s) | StatementTypeSignature (TypeSignature s)
| StatementImport (Import s) | StatementImport (Import s)
| StatementDataType (DataTypeDef s) | StatementInductive (InductiveDef s)
| StatementModule (Module s 'ModuleLocal) | StatementModule (Module s 'ModuleLocal)
| StatementOpenModule OpenModule | StatementOpenModule OpenModule
| StatementFunctionClause (FunctionClause s) | StatementFunctionClause (FunctionClause s)
@ -186,7 +186,7 @@ deriving stock instance (Lift (ExpressionType s), Lift (SymbolType s)) => Lift (
type DataConstructorName s = SymbolType s type DataConstructorName s = SymbolType s
type DataTypeName s = SymbolType s type InductiveName s = SymbolType s
data DataConstructorDef (s :: Stage) = DataConstructorDef data DataConstructorDef (s :: Stage) = DataConstructorDef
{ constructorName :: DataConstructorName s, { constructorName :: DataConstructorName s,
@ -201,33 +201,33 @@ deriving stock instance (Ord (ExpressionType s), Ord (SymbolType s)) => Ord (Dat
deriving stock instance (Lift (ExpressionType s), Lift (SymbolType s)) => Lift (DataConstructorDef s) deriving stock instance (Lift (ExpressionType s), Lift (SymbolType s)) => Lift (DataConstructorDef s)
data DataTypeParameter (s :: Stage) = DataTypeParameter data InductiveParameter (s :: Stage) = InductiveParameter
{ dataTypeParameterName :: SymbolType s, { inductiveParameterName :: SymbolType s,
dataTypeParameterType :: ExpressionType s inductiveParameterType :: ExpressionType s
} }
deriving stock instance (Show (ExpressionType s), Show (SymbolType s)) => Show (DataTypeParameter s) deriving stock instance (Show (ExpressionType s), Show (SymbolType s)) => Show (InductiveParameter s)
deriving stock instance (Eq (ExpressionType s), Eq (SymbolType s)) => Eq (DataTypeParameter s) deriving stock instance (Eq (ExpressionType s), Eq (SymbolType s)) => Eq (InductiveParameter s)
deriving stock instance (Ord (ExpressionType s), Ord (SymbolType s)) => Ord (DataTypeParameter s) deriving stock instance (Ord (ExpressionType s), Ord (SymbolType s)) => Ord (InductiveParameter s)
deriving stock instance (Lift (ExpressionType s), Lift (SymbolType s)) => Lift (DataTypeParameter s) deriving stock instance (Lift (ExpressionType s), Lift (SymbolType s)) => Lift (InductiveParameter s)
data DataTypeDef (s :: Stage) = DataTypeDef data InductiveDef (s :: Stage) = InductiveDef
{ dataTypeName :: DataTypeName s, { inductiveName :: InductiveName s,
dataTypeParameters :: [DataTypeParameter s], inductiveParameters :: [InductiveParameter s],
dataTypeType :: Maybe (ExpressionType s), inductiveType :: Maybe (ExpressionType s),
dataTypeConstructors :: [DataConstructorDef s] inductiveConstructors :: [DataConstructorDef s]
} }
deriving stock instance (Show (ExpressionType s), Show (SymbolType s)) => Show (DataTypeDef s) deriving stock instance (Show (ExpressionType s), Show (SymbolType s)) => Show (InductiveDef s)
deriving stock instance (Eq (ExpressionType s), Eq (SymbolType s)) => Eq (DataTypeDef s) deriving stock instance (Eq (ExpressionType s), Eq (SymbolType s)) => Eq (InductiveDef s)
deriving stock instance (Ord (ExpressionType s), Ord (SymbolType s)) => Ord (DataTypeDef s) deriving stock instance (Ord (ExpressionType s), Ord (SymbolType s)) => Ord (InductiveDef s)
deriving stock instance (Lift (ExpressionType s), Lift (SymbolType s)) => Lift (DataTypeDef s) deriving stock instance (Lift (ExpressionType s), Lift (SymbolType s)) => Lift (InductiveDef s)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Pattern -- Pattern

View File

@ -82,7 +82,7 @@ statement =
<|> (StatementOpenModule <$> openModule) <|> (StatementOpenModule <$> openModule)
<|> (StatementEval <$> eval) <|> (StatementEval <$> eval)
<|> (StatementImport <$> import_) <|> (StatementImport <$> import_)
<|> (StatementDataType <$> dataTypeDef) <|> (StatementInductive <$> inductiveDef)
<|> (StatementPrint <$> printS) <|> (StatementPrint <$> printS)
<|> (StatementModule <$> moduleDef) <|> (StatementModule <$> moduleDef)
<|> (StatementAxiom <$> axiomDef) <|> (StatementAxiom <$> axiomDef)
@ -304,21 +304,21 @@ lambda = do
-- Data type construction declaration -- Data type construction declaration
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
dataTypeDef :: MonadParsec e Text m => m (DataTypeDef 'Parsed) inductiveDef :: MonadParsec e Text m => m (InductiveDef 'Parsed)
dataTypeDef = do inductiveDef = do
kwInductive kwInductive
dataTypeName <- symbol inductiveName <- symbol
dataTypeParameters <- P.many dataTypeParam inductiveParameters <- P.many inductiveParam
dataTypeType <- optional (kwColon >> expressionAtoms) inductiveType <- optional (kwColon >> expressionAtoms)
dataTypeConstructors <- braces $ P.sepEndBy constructorDef kwSemicolon inductiveConstructors <- braces $ P.sepEndBy constructorDef kwSemicolon
return DataTypeDef {..} return InductiveDef {..}
dataTypeParam :: MonadParsec e Text m => m (DataTypeParameter 'Parsed) inductiveParam :: MonadParsec e Text m => m (InductiveParameter 'Parsed)
dataTypeParam = parens $ do inductiveParam = parens $ do
dataTypeParameterName <- symbol inductiveParameterName <- symbol
kwColon kwColon
dataTypeParameterType <- expressionAtoms inductiveParameterType <- expressionAtoms
return DataTypeParameter {..} return InductiveParameter {..}
constructorDef :: MonadParsec e Text m => m (DataConstructorDef 'Parsed) constructorDef :: MonadParsec e Text m => m (DataConstructorDef 'Parsed)
constructorDef = do constructorDef = do

View File

@ -168,7 +168,7 @@ ppStatement s = case s of
StatementOperator op -> ppOperatorSyntaxDef op StatementOperator op -> ppOperatorSyntaxDef op
StatementTypeSignature sig -> ppTypeSignature sig StatementTypeSignature sig -> ppTypeSignature sig
StatementImport i -> ppImport i StatementImport i -> ppImport i
StatementDataType d -> ppDataTypeDef d StatementInductive d -> ppInductiveDef d
StatementModule m -> ppModule m StatementModule m -> ppModule m
StatementOpenModule o -> ppOpen o StatementOpenModule o -> ppOpen o
StatementFunctionClause c -> ppFunctionClause c StatementFunctionClause c -> ppFunctionClause c
@ -218,25 +218,25 @@ ppDataConstructorDef DataConstructorDef {..} = do
constructorType' <- ppExpression constructorType constructorType' <- ppExpression constructorType
return $ constructorName' <+> kwColon <+> constructorType' return $ constructorName' <+> kwColon <+> constructorType'
ppDataTypeDef :: forall r. Members '[Reader Options] r => DataTypeDef 'Scoped -> Sem r (Doc Ann) ppInductiveDef :: forall r. Members '[Reader Options] r => InductiveDef 'Scoped -> Sem r (Doc Ann)
ppDataTypeDef DataTypeDef {..} = do ppInductiveDef InductiveDef {..} = do
dataTypeName' <- ppSSymbol dataTypeName inductiveName' <- ppSSymbol inductiveName
dataTypeParameters' <- hsep <$> mapM ppDataTypeParameter dataTypeParameters inductiveParameters' <- hsep <$> mapM ppInductiveParameter inductiveParameters
dataTypeType' <- ppTypeType inductiveType' <- ppTypeType
dataTypeConstructors' <- ppBlock ppDataConstructorDef dataTypeConstructors inductiveConstructors' <- ppBlock ppDataConstructorDef inductiveConstructors
return $ return $
kwInductive <+> dataTypeName' <+> dataTypeParameters' <+?> dataTypeType' kwInductive <+> inductiveName' <+> inductiveParameters' <+?> inductiveType'
<+> dataTypeConstructors' <+> inductiveConstructors'
where where
ppTypeType :: Sem r (Maybe (Doc Ann)) ppTypeType :: Sem r (Maybe (Doc Ann))
ppTypeType = case dataTypeType of ppTypeType = case inductiveType of
Nothing -> return Nothing Nothing -> return Nothing
Just e -> Just . (kwColon <+>) <$> ppExpression e Just e -> Just . (kwColon <+>) <$> ppExpression e
ppDataTypeParameter :: DataTypeParameter 'Scoped -> Sem r (Doc Ann) ppInductiveParameter :: InductiveParameter 'Scoped -> Sem r (Doc Ann)
ppDataTypeParameter DataTypeParameter {..} = do ppInductiveParameter InductiveParameter {..} = do
dataTypeParameterName' <- ppSSymbol dataTypeParameterName inductiveParameterName' <- ppSSymbol inductiveParameterName
dataTypeParameterType' <- ppExpression dataTypeParameterType inductiveParameterType' <- ppExpression inductiveParameterType
return $ parens (dataTypeParameterName' <+> kwColon <+> dataTypeParameterType') return $ parens (inductiveParameterName' <+> kwColon <+> inductiveParameterType')
dotted :: [Doc Ann] -> Doc Ann dotted :: [Doc Ann] -> Doc Ann
dotted = concatWith (surround kwDot) dotted = concatWith (surround kwDot)

View File

@ -28,7 +28,7 @@ data ModuleScopeInfo = ModuleScopeInfo
-- | constructors introduced by inductive definitions (E.g. zero; suc). -- | constructors introduced by inductive definitions (E.g. zero; suc).
_syntaxConstructors :: HashSet (DataConstructorName 'Parsed), _syntaxConstructors :: HashSet (DataConstructorName 'Parsed),
-- | data types introduced by inductive definitions (E.g. ). -- | data types introduced by inductive definitions (E.g. ).
_syntaxDataTypes :: HashSet (DataTypeName 'Parsed), _syntaxInductives :: HashSet (InductiveName 'Parsed),
-- | function names in scope. Function names are introduced with function clauses. -- | function names in scope. Function names are introduced with function clauses.
_syntaxFunctions :: HashSet (FunctionName 'Parsed), _syntaxFunctions :: HashSet (FunctionName 'Parsed),
-- | locally defined modules. Imported modules are not included. -- | locally defined modules. Imported modules are not included.
@ -281,23 +281,23 @@ moduleScopeInfo absPath sModule = ModuleScopeInfo {..}
where where
getFun :: Statement 'Scoped -> Maybe (FunctionName 'Parsed) getFun :: Statement 'Scoped -> Maybe (FunctionName 'Parsed)
getFun s = case s of getFun s = case s of
-- StatementDataType DataTypeDef {..} → HashSet.fromList (map constructorName dataTypeConstructors) -- StatementInductive InductiveDef {..} → HashSet.fromList (map constructorName inductiveConstructors)
_ -> undefined _ -> undefined
_syntaxConstructors :: HashSet (DataConstructorName 'Parsed) _syntaxConstructors :: HashSet (DataConstructorName 'Parsed)
_syntaxConstructors = mconcat (map getConstrs stmts) _syntaxConstructors = mconcat (map getConstrs stmts)
where where
getConstrs :: Statement 'Scoped -> HashSet (DataConstructorName 'Parsed) getConstrs :: Statement 'Scoped -> HashSet (DataConstructorName 'Parsed)
getConstrs s = case s of getConstrs s = case s of
StatementDataType DataTypeDef {..} -> StatementInductive InductiveDef {..} ->
HashSet.fromList HashSet.fromList
(map (S._nameConcrete . constructorName) dataTypeConstructors) (map (S._nameConcrete . constructorName) inductiveConstructors)
_ -> mempty _ -> mempty
_syntaxDataTypes :: HashSet (DataTypeName 'Parsed) _syntaxInductives :: HashSet (InductiveName 'Parsed)
_syntaxDataTypes = HashSet.fromList (mapMaybe getDT stmts) _syntaxInductives = HashSet.fromList (mapMaybe getDT stmts)
where where
getDT :: Statement 'Scoped -> Maybe (DataTypeName 'Parsed) getDT :: Statement 'Scoped -> Maybe (InductiveName 'Parsed)
getDT s = case s of getDT s = case s of
StatementDataType DataTypeDef {..} -> Just (S._nameConcrete dataTypeName) StatementInductive InductiveDef {..} -> Just (S._nameConcrete inductiveName)
_ -> Nothing _ -> Nothing
_syntaxOperators :: HashMap Symbol Fixity _syntaxOperators :: HashMap Symbol Fixity
_syntaxOperators = HashMap.fromList (mapMaybe getDef stmts) _syntaxOperators = HashMap.fromList (mapMaybe getDef stmts)
@ -381,45 +381,45 @@ checkConstructorDef DataConstructorDef {..} = do
constructorType = constructorType' constructorType = constructorType'
} }
checkDataTypeDef :: checkInductiveDef ::
Members '[Error ScopeError, State Scope, State ScopeState] r => Members '[Error ScopeError, State Scope, State ScopeState] r =>
DataTypeDef 'Parsed -> InductiveDef 'Parsed ->
Sem r (DataTypeDef 'Scoped) Sem r (InductiveDef 'Scoped)
checkDataTypeDef DataTypeDef {..} = do checkInductiveDef InductiveDef {..} = do
localScope $ checkDataTypeRec dataTypeParameters localScope $ checkInductiveRec inductiveParameters
where where
checkDataTypeRec :: checkInductiveRec ::
forall r. forall r.
Members '[Error ScopeError, State Scope, State ScopeState, Reader LocalVars] r => Members '[Error ScopeError, State Scope, State ScopeState, Reader LocalVars] r =>
[DataTypeParameter 'Parsed] -> [InductiveParameter 'Parsed] ->
Sem r (DataTypeDef 'Scoped) Sem r (InductiveDef 'Scoped)
checkDataTypeRec dtp = go dtp [] checkInductiveRec dtp = go dtp []
where where
go :: [DataTypeParameter 'Parsed] -> [DataTypeParameter 'Scoped] -> Sem r (DataTypeDef 'Scoped) go :: [InductiveParameter 'Parsed] -> [InductiveParameter 'Scoped] -> Sem r (InductiveDef 'Scoped)
go params dataTypeParameters' = go params inductiveParameters' =
case params of case params of
-- More params to check -- More params to check
(DataTypeParameter {..} : ps) -> do (InductiveParameter {..} : ps) -> do
dataTypeParameterType' <- checkParseExpressionAtoms dataTypeParameterType inductiveParameterType' <- checkParseExpressionAtoms inductiveParameterType
dataTypeParameterName' <- freshVariable dataTypeParameterName inductiveParameterName' <- freshVariable inductiveParameterName
let param' = let param' =
DataTypeParameter InductiveParameter
{ dataTypeParameterType = dataTypeParameterType', { inductiveParameterType = inductiveParameterType',
dataTypeParameterName = dataTypeParameterName' inductiveParameterName = inductiveParameterName'
} }
withBindLocalVariable (LocalVariable dataTypeParameterName') $ withBindLocalVariable (LocalVariable inductiveParameterName') $
go ps (dataTypeParameters' ++ [param']) go ps (inductiveParameters' ++ [param'])
-- All params have been checked -- All params have been checked
[] -> do [] -> do
dataTypeType' <- sequence (checkParseExpressionAtoms <$> dataTypeType) inductiveType' <- sequence (checkParseExpressionAtoms <$> inductiveType)
dataTypeName' <- bindInductiveSymbol dataTypeName inductiveName' <- bindInductiveSymbol inductiveName
dataTypeConstructors' <- mapM checkConstructorDef dataTypeConstructors inductiveConstructors' <- mapM checkConstructorDef inductiveConstructors
return return
DataTypeDef InductiveDef
{ dataTypeName = dataTypeName', { inductiveName = inductiveName',
dataTypeParameters = dataTypeParameters', inductiveParameters = inductiveParameters',
dataTypeType = dataTypeType', inductiveType = inductiveType',
dataTypeConstructors = dataTypeConstructors' inductiveConstructors = inductiveConstructors'
} }
checkTopModule :: checkTopModule ::
@ -875,7 +875,7 @@ checkStatement s = case s of
StatementOperator opDef -> StatementOperator opDef <$ checkOperatorSyntaxDef opDef StatementOperator opDef -> StatementOperator opDef <$ checkOperatorSyntaxDef opDef
StatementTypeSignature tySig -> StatementTypeSignature <$> checkTypeSignature tySig StatementTypeSignature tySig -> StatementTypeSignature <$> checkTypeSignature tySig
StatementImport imp -> StatementImport <$> checkImport imp StatementImport imp -> StatementImport <$> checkImport imp
StatementDataType dt -> StatementDataType <$> checkDataTypeDef dt StatementInductive dt -> StatementInductive <$> checkInductiveDef dt
StatementModule dt -> StatementModule <$> checkLocalModule dt StatementModule dt -> StatementModule <$> checkLocalModule dt
StatementOpenModule open -> StatementOpenModule open <$ checkOpenModule open StatementOpenModule open -> StatementOpenModule open <$ checkOpenModule open
StatementFunctionClause clause -> StatementFunctionClause <$> checkFunctionClause clause StatementFunctionClause clause -> StatementFunctionClause <$> checkFunctionClause clause