Because Haskell supports infinite lists, our recursion doesn't really have to have an edge condition.

Recursive Data Types. The binary tree data type is often used for storing data in a sorted order, to allow efficient searching — for example, a telephone directory. I’ve spoken about the List Data Type previously in the Haskell for Beginners: Lists and Comprehensions post, but we need to know a little more about them before we can apply our newly found recursive knowledge to them. How the list is built.

Data types can be recursive, that is, defined in terms of themselves. Grow a Tree In Computer Science, trees grow upside-down. Now you know a little about Recursion its time we use this knowledge for good - lets use it with a Haskell Favorite, Lists!.

All Haskell values are "first-class"---they may be passed as arguments to functions, returned as results, placed in data structures, etc. A list is either empty, or a single element followed by a remaining list. But if it doesn't have it, it will either keep churning at something infinitely or produce an infinite data structure, like an infinite list. Haskell types, on the other hand, are not first-class. A recursive data type (also known as a recursively-defined, inductively-defined or inductive data type) is a data type for values that may contain other values of the same type. We could define our own list type like so: data IntList = Empty | … The good thing about infinite lists though is that we can cut them where we want. In fact, we have already seen a recursive type—the type of lists. The unique root is at the top, and the leaves are at the bottom. We are going to define a Haskell data type for trees, storing integer values. Types in a sense describe values, and the association of a value with its type is called a typing .