-
Notifications
You must be signed in to change notification settings - Fork 1
/
testList.lp
46 lines (35 loc) · 840 Bytes
/
testList.lp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function empty : [Int] ;
empty := [] ;
function lst1 : [Bool] ;
lst1 := [True,False,True] ;
function head : [Int] -> Int ;
head [] := 0 ;
head (x:xs) := x ;
function lstPat1 : [Int] -> Int ;
lstPat1 ys := case ys of
[] -> 0 ;
(1:xs) -> 1 ;
(x:[]) -> x ;
(_:xs) -> 3 ; ;
function lstPat2 : [Int] -> Int ;
lstPat2 [] := 0 ;
lstPat2 (1:xs) := 1 ;
lstPat2 (x:[]) := x ;
lstPat2 (_:xs) := 3 ;
function sum : [Int] -> Int ;
sum [] := 0 ;
sum (x:xs) := x + sum xs ;
function last : [Int] -> Int ;
last ys := case ys of
(x:[]) -> x ;
(x:xs) -> last xs ;;
-- Can't load file when these functions are included
----------------------------------------------------
{-
-- list of ELiteral
function lst2 : [Int] ;
lst2 := [1,2,3] ;
-- list of ETuple
function lst3 : [Tuple] ;
lst3 := [(1,2), (3,4)] ;
-}