Skip to content

Use Unicode Greek alphabets for visual representation of CGP field types#85

Merged
soareschen merged 7 commits intomainfrom
unicode-types
Apr 1, 2025
Merged

Use Unicode Greek alphabets for visual representation of CGP field types#85
soareschen merged 7 commits intomainfrom
unicode-types

Conversation

@soareschen
Copy link
Collaborator

@soareschen soareschen commented Apr 1, 2025

Summary

This PR redefines the base definition of field types to use single Unicode character to represent the type. This significantly simplifies the visual representation of field types in error messages and IDEs, so that they can be read more easily.

Mappings

The field types now have the following mapping:

  • Char - ι
  • Index - δ
  • Cons - π
  • Nil - ε
  • Either - σ
  • Void - θ
  • Field - ω

ASCII Names

The Unicode field types still re-export their original ASCII names using pub use. This means that all existing code that use the original ASCII names will continue to work.

Changes to Char and symbol!

The Char type has been redesigned to combine with Cons, so that the tail type is in the second argument of Char. This allows the symbol types generated from symbol! to have cleaner display, together with the use of ι to further shorten the representation.

Considerations

I have chosen to use lowercase instead of uppercase Greek characters for the field types, as they offer cleaner visual representation. The key consieration is that the field types should "look" almost invisible, so that the readers can focus on the "shape" of the overall field types, instead of the individual characters.

Example

Consider the original expansion of the macro for the following product type:

Product! [
    Field<symbol!("name"), String>,
    Field<symbol!("age"), u64>,
]

The original expansion would look like:

Cons<Field<Char<'n', Char<'a', Char<'m', Char<'e', Nil>>>>, String>, Cons<Field<Char<'a', Char<'g', Char<'e', Nil>>>, u8>, Nil>>

But the visual representation of the same field type would be:

π<ω<ι<'n', ι<'a', ι<'m', ι<'e', ε>>>>, String>, π<ω<ι<'a', ι<'g', ι<'e', ε>>>, u8>, ε>>

As we can see, the Unicode types make it much easier to figure out what the field type is, assuming once we are familiarized with what each Greek character means.

@soareschen soareschen marked this pull request as ready for review April 1, 2025 21:37
@soareschen soareschen merged commit e133526 into main Apr 1, 2025
5 checks passed
@soareschen soareschen deleted the unicode-types branch April 1, 2025 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant