X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=examples%2Fexample.spl;h=e71c2162f4c473f00c81296158134ed198e57b51;hb=a363f872ee96379d8b0b9b14cb6faec9d74e7e92;hp=6cebe905f39b6109104862e965f051a0f6c1d5b6;hpb=90e3f306b5813ff66f8249ba243a8a4220c915fe;p=cc1516.git diff --git a/examples/example.spl b/examples/example.spl index 6cebe90..e71c216 100644 --- a/examples/example.spl +++ b/examples/example.spl @@ -2,6 +2,15 @@ Three ways to implement the f acto rial function in SPL. First the recursive version . */ +Int r = 1; +Char r = 1; +Int r = -1; +Void r = 0; +Bool r = !True; +Bool r = -True; +//var facN = 1; +//var ok = True; + facR(n) :: Int -> Int { if (n < 2) { return 1; @@ -10,6 +19,7 @@ facR(n) :: Int -> Int { } } + //The iterative version of the factorial function facl ( n ) :: Int -> Int { var r = 1; @@ -43,7 +53,7 @@ facL (n) :: Int -> Int { } //Generates a list of integers from the first to the last argument -fromTo (from, to) :: Int Int -> [Int] { +fromTo (from, to) :: Int -> Int -> [Int] { if(from <= to){ return from:fromTo(from+1, to); } else { @@ -73,7 +83,7 @@ swap(tuple) :: (a, a) -> (a, a){ } //list append -append(l1, l2) :: [t] [t] -> [t] { +append(l1, l2) :: [t] -> [t] -> [t] { if(isEmpty(l1)){ return l2; } else { @@ -84,7 +94,7 @@ append(l1, l2) :: [t] [t] -> [t] { //square the odd numbers in a list and remove the even members squareOddNumbers(list) :: [Int] -> [Int] { - while(!isEmpty (list) && list.hd % 2=0){ + while(!isEmpty (list) && list.hd % 2==0){ list=list.tl; } if(!isEmpty(list)){