The function `foldr`

is a versatile function for list processing:

foldr cons nil [] = nil foldr cons nil (x:xs) = cons x (foldr cons nil xs)

It replaces every `(:)`

with `cons`

and `[]`

with `nil`

. If you apply this idea to FlatCurry dataterms instead of lists, you can define selectors, test and update operations and useful auxiliary functions based on one primitive for each datatype inspired by the `foldr`

idea. You get over 800 lines of boring code and you never need to rewrite it for your program transformations. Just watch FlatCurryGoodies and use the versatile predefined functions to do exactly what you need.

As an example consider a transformation function for type expressions:

trTypeExpr tvar tcons functype (TVar n) = tvar n trTypeExpr tvar tcons functype (TCons name args) = tcons name (map (trTypeExpr tvar tcons functype) args) trTypeExpr tvar tcons functype (FuncType from to) = functype (f from) (f to) where f = trTypeExpr tvar tcons functype

Now you can specialize this function to rename all indices of type variables with a rename function `rename`

:

rnmAllVarsInTypeExpr rename = trTypeExpr (TVar . rename) TCons FuncType

Many other typical transformations can be written using such `tr...`

operations. I hope these utilities can help you writing clear and brief code!