Skip to content

Constrained representation types #354

@brendanzab

Description

@brendanzab

It it might eventually be useful to be able to ‘constrain’ representation types using something like Format { Repr = ... }
(this popped up in other approaches to figuring out the font tables).

This could allow us to write formats like:

  • join16 : fun (len : U16) (A : Type) -> Array16 len (Format { Repr = A }) -> Format { Repr = Array16 len A }

As Fathom is based on intensional type theory implementing such a construct could require a bit of thought – I'm not entirely clear on what the interactions and difficulties are, or if there are ways to simplify this.

A weird connection to module systems and associated types

This reminds me a bit of a limited form of:

This kind of makes sense if you imagine a Format to be a builtin/hard-coded module type:

let Format = {
    Repr : Type,
    decode : Decoder Repr,
    encode : Encoder Repr,
};

You could imagine extending this 'module' to support sizes too:

let Format = {
    Repr : Type,
    size : Size,
    decode : Decoder Repr size,
    encode : Encoder Repr size,
};

Note: I'm absolutely not recommending we implement Formats in this way - I just find it an interesting perspective!


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions