Idris2/tests/idris2/builtin/builtin010/Test.idr

26 lines
501 B
Idris
Raw Normal View History

%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