-- The primitive recursive functions -- -- Raul Rojas ------------------------------------------ -- Zero function clr [x] = 0 --Succesor function suc [x] = x+1 --Projection functions. Tuples are represented by lists p::Int->[Int]->Int p 1 (a:b) = a p n (a:b) = p (n-1) b -- Operations ------------------------| -- Composition compose g fs xs = g (app fs xs) -- Apply a list of functions to argument a app [] a = [] app (f:fs) a = (f a):(app fs a) -- primitive recursion pr::([Int]->Int)->([Int]->Int)->([Int]->Int)->[Int]->Int pr phi psi chi ( 0 :xs) = psi xs pr phi psi chi ((y+1):xs) = chi ((phi (y:xs)):y:xs) -- Convert an argument to a list arg1 x = [x] ------------------------| some primitive recursive functions --preddecessor predd::[Int]->Int predd = pr predd (const 0) (p 2) --Addition add::[Int]->Int add = pr add (p 1) (compose suc [(p 1)])