Forward declaration syntax for data

Allow:
```newt
data Foo : U
```
as a forward declaration for data. (The `Foo : U` syntax still works for
now.)
This commit is contained in:
2026-02-07 07:52:00 -08:00
parent 79ab29f090
commit 0c206a94ab
3 changed files with 13 additions and 11 deletions

View File

@@ -76,17 +76,15 @@ instance HasFC Raw where
data Import = MkImport FC Name
Telescope : U
Telescope = List (BindInfo × Raw)
data Decl
= TypeSig FC (List Name) Raw
| FunDef FC Name (List (Raw × Maybe Raw))
| DCheck FC Raw Raw
| Data FC Name Raw (List Decl)
-- TODO maybe add Telescope (before `:`) and auto-add to constructors...
| Data FC Name Raw (Maybe $ List Decl)
| ShortData FC Raw (List Raw)
| PType FC Name (Maybe Raw)
| PFunc FC Name (List String) Raw String
@@ -247,7 +245,8 @@ instance Pretty Decl where
prettyPair : Raw × Maybe Raw Doc
prettyPair (a, Nothing) = pretty a
prettyPair (a, Just b) = pretty a <+> text "=" <+> pretty b
pretty (Data _ nm x xs) = text "data" <+> text nm <+> text ":" <+> pretty x <+> (nest 2 $ text "where" </> stack (map pretty xs))
pretty (Data _ nm x Nothing) = text "data" <+> text nm <+> text ":" <+> pretty x
pretty (Data _ nm x (Just xs)) = text "data" <+> text nm <+> text ":" <+> pretty x <+> (nest 2 $ text "where" </> stack (map pretty xs))
pretty (DCheck _ x y) = text "#check" <+> pretty x <+> text ":" <+> pretty y
pretty (PType _ nm ty) = text "ptype" <+> text nm <+> (maybe empty (\ty => text ":" <+> pretty ty) ty)
pretty (PFunc _ nm Nil ty src) = text "pfunc" <+> text nm <+> text ":" <+> nest 2 (pretty ty <+> text ":=" <+/> text (show src))