yeslogic / fathom

🚧 (Alpha stage software) A declarative data definition language for formally specifying binary data formats. 🚧
Apache License 2.0
259 stars 14 forks source link

Remove Type-in-Type #316

Open brendanzab opened 2 years ago

brendanzab commented 2 years ago

Currently Fathom implements Type : Type. This is a common approach for making prototype implementations of dependently typed languages, but it's far too expressive for a binary data description language. It also introduces well-known paradoxes that can lead to non-termination. Instead we should only ever allow Type to appear on the right-hand side of the colon. This could involve adding a check_type function to the elaborator:

pub fn check_type(&mut self, surface_term: &Term<'_, ByteRange>) -> core::Term<'arena> {
    ...
}

Similarly it might also make sense to remove the Format : Type rule, instead checking that Format is a type in the check_type function. This prevent us from defining binary formats that describe other binary formats, but these are probably exceedingly rare, and it's probably good to be more conservative at this point.

brendanzab commented 1 year ago

I was looking into restricting fathom to only allow us to talk about “small types” (The Little Typer does this in its Pie language). I was running into issues with unification introducing Types however.

I think that we could introduce a restricted universe hierarchy with just a universe of small types (Type), and a universe of large types (Type 1). This is what XML does (a core language for SML by Harper and Mitchell). 1ML does something similar (but has not dependent types). As in Idris there would be no syntax to introduce Type 1 universes, but we also would not attempt to ‘solve’ universe levels to keep things simpler. Formats would be considered ‘large types’ (as they can contain types). I also think records should only be permitted to contain small types for the time being for simplicity. I’ve implemented a simple approach to checking universes in wip-compile-stratify/Core.ml.