churf/test_program.crf
2023-03-29 15:12:33 +02:00

38 lines
No EOL
742 B
Text

-- a simple list data type containing ints
data List () where {
Cons : Int -> List () -> List ()
Nil : List ()
};
main = head (repeat 10 5);
head : List () -> Int ;
head x = case x of {
Cons h _ => h ;
};
repeat : Int -> Int -> List () ;
repeat x n = case n of {
0 => Nil ;
n => Cons x (repeat x (n + minusOne)) ;
};
minusOne : Int ;
minusOne = 9223372036854775807 + 9223372036854775807 + 1;
-- take the length of a list
length : List () -> Int ;
length x = case x of {
Cons _ xs => 1 + length xs ;
Nil => 0 ;
};
-- sum a list
sum : List () -> Int ;
sum x = case x of {
Cons a xs => a + sum xs ;
Nil => 0 ;
};
-- sum + length of a list
sumlength: List () -> Int ;
sumlength x = sum x + length x ;