OPFN
  • What is this thing?
    • A New Internet
    • Architecture
    • Runtime
  • Installation
    • Environment Setup
  • Quickstart Tutorial
    • "Hello World" Cog
    • Booting, Starting, Caching
    • JSON
    • Cog webserver end-to-end
  • Databases / Cogs
    • Introduction
    • Creating a Cog
    • Using a Cog
    • Inter-Cog Communication
  • Sire Reference
    • Intro
    • Runes
    • Miscellaneous
    • Standard Library
      • Bits (Booleans)
      • Natural Numbers
      • Comparisons
      • Characters and Strings
      • Rows
      • Lists
      • Either
      • Maybe
      • Sets
      • KV Tables
      • Pads
      • Bars
      • Types
  • Deeper
    • Nat Representations
    • R-Expressions
    • Seed files
    • Jets
    • Boot process
    • UI files
  • PLAN
    • In Depth
    • Definition
Powered by GitBook
On this page
  • Type Tags
  • typeTag
  • {#datatype}
  • {#datacase}
  • {#record}
  1. Sire Reference
  2. Standard Library

Types

Type Tags

Encodings for primitive types.

pinTag=0
lawTag=1
appTag=2
natTag=3
barTag=4
rowTag=5
tabTag=6
cowTag=7
setTag=8

typeTag

Returns the type tag of a given value.

typeTag 42            == 3 ; natTag
typeTag [1 2 3]       == 5 ; rowTag
typeTag #[a=1 b=2]    == 6 ; tabTag

{#datatype}

Macro for defining new datatypes.

# datatype (Maybe a)
* NONE
* SOME x:a

# datatype (List a)
* NIL
* CONS head:a tail:(List a)

# datatype (Tree a)
* LEAF val:a
* NODE left:(Tree a) right:(Tree a)

{#datacase}

Macro for pattern matching on datatypes.

# datacase (SOME 5)
* NONE     0
* (SOME x) x

# datacase myList
* NIL         0
* (CONS x xs) (add x (length xs))

# datacase myEither
* (LEFT err)  (handleError err)
* (RIGHT val) (processValue val)

{#record}

Macro for defining record types.

# record (Point2D)
| POINT
* x : Nat
* y : Nat

# record (Person)
| PERSON
* name : Str
* age : Nat

# record (Config a)
| CONFIG
* enabled : Bit
* value : a
PreviousBarsNextNat Representations

Last updated 9 months ago