1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-11 08:25:46 +03:00
juvix/examples/syntax.miniju

51 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- The syntax is very similar to that of Agda. However, we need some extra ';'
module Example where
-- The natural numbers can be inductively defined thus:
data : Type 0 ;
| zero :
| suc : ;
-- A list of elements with typed size:
data Vec (A : Type) : → Type 0 ;
| nil : A → Vec A zero
| cons : (n : ) → A → Vec A n → Vec A (suc n) ;
module -Ops where
infixl 6 + ;
+ : ;
+ zero b = b ;
+ (suc a) b = suc (a + b) ;
infixl 7 * ;
* : ;
* zero b = zero ;
* (suc a) b = b + a * b ;
end
module M1 (A : Type 0) where
aVec : → Type 0 ;
aVec = Vec A ;
end
module Bot where
data ⊥ : Type 0 ;
end
open module M1 ;
two : ;
two = suc (suc zero) ;
id : (A : Type) → A → A ;
id _ = λ x → x ;
natVec : aVec (cons zero) ;
natVec = cons (two * two + one) nil ;
-- The 'where' part belongs to the clause
where
open module -Ops ;
one : ;
one = suc zero ;
end