polymorphism

examples/polymorphism.omg

examples/polymorphism.omg28 lines
1{-  Universe polymorphism.
2
3        omegyu type examples/polymorphism.omg
4
5    `Type` is short for `Type 0`, the type of ordinary types; `Type 0` itself
6    has type `Type 1`, and so on.  A definition can abstract over the
7    universe level it works at, with a variable of type `Level`.
8-}
9
10-- The identity function, at every universe level.
11let id : forall {l : Level} {a : Type l} -> a -> a = \x -> x
12
13-- A pair of two things of the same type, whatever its level.
14let Twice : forall {l : Level} -> Type l -> Type l = \a -> a * a
15
16let twice : forall {l : Level} {a : Type l} -> a -> Twice a = \x -> (x, x)
17
18in  { -- At level 0: a number.
19      number = id 1
20    , -- At level 1: a type.
21      type = id Natural
22    , -- At level 2: the type of types.
23      kind = id Type
24    , numbers = twice 1
25    , types = twice Natural
26    , -- `id` applied to itself, instantiated at two different types.
27      self = id (id @Natural) 2
28    }
Your result
Complete file: examples/polymorphism.omg · with imports