Skip to content

Sum types? #411

Open
Open
@Kmeakin

Description

@Kmeakin

Fathom currently has anonymous product types (records), but no (convenient) way of expressing sum types.

Potential solutions

  • Do nothing. Encode sum types as dependent records (eg let Option : Type -> Type = fun T => {tag : Bool, value : if tag then T else {})
  • Anonymous sum types, dual to records: (eg let Option : Type -> Type = fun T => sum {None : {}, Some : T})
  • Algebraic data types a la Haskell, ML, Rust etc
  • Polymorphic variants

Design considerations

  • Are they ergonomic to use?
  • Can they express recursion?
  • Can they be compiled efficiently?
  • Nominal or structural?
  • Row polymorphism?
  • First class labels?

Prior Art

  • (Generalized) Algebraic data types: Haskell, Agda, Coq, Idris, Ocaml
  • Anonymous sum types: Haskell, Dhall
  • Polymorphic variants: Ocaml

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