Idris2/tests/idris2/builtin/builtin010/Test.idr
2023-09-07 14:57:22 +01:00

26 lines
501 B
Idris

%hide Prelude.integerToNat
data MyNat : Type where
Z : MyNat
S : MyNat -> MyNat
%builtin Natural MyNat
integerToMyNat : Integer -> MyNat
integerToMyNat i = if i <= 0
then Z
else S $ integerToMyNat (i - 1)
%builtin IntegerToNatural integerToMyNat
natToMyNat : Nat -> MyNat
natToMyNat Z = Z
natToMyNat (S k) = S $ natToMyNat k
%builtin IntegerToNatural natToMyNat
integerToNotNat : Integer -> Maybe String
integerToNotNat x = Just "Boo"
%builtin IntegerToNatural integerToNotNat