A Note On Different Relation Of Function Essays

1433 Words Dec 18th, 2016 6 Pages
Recursions with Folds
Apart from using the recursion directly, fold is available to occur recursion scheme, which applies a function to data structure/Functor to manipulate its contents. Figure 1
The above illustrates the summary of different relation of function. Below we will focus on further explaining of how to isolate the recursions from the code in order to gain the benefit of convenience, which is easier to control, repair and further develop the code.
In (inception) & Fix (fixpoint)
The whole idea if In and Fix is all about where the recursion of code performs in the data type, which isolate the recursion to a single spot, usually represented by parameter k.
First of all, we would have a simple code with direct recursions and then compare with the recursion by using In and Fix.
Direct Recursion data List a = Empty | Cons a (List a)
Cons 10 (Cons 20 Empty)
The code above defines the data of list a which can be either empty or consist of a with the recursion of calling back the list a. ie. This is kind of bad recursion that we want to isolate later on. In this example, it consists of an integer of 10, an integer of 20 by the recursion, list a, and finally stop the recursion by Empty. The Cons function will keep recusing by and updating the data for looping until Empty function.
Empty :: List a
Cons :: a -> List -> List a
The above situation, the recursion remain the same feature but is isolated by defining their data type.. This function can only apply in…

Related Documents