Search code examples
haskellrecursiontreeinfinitealgebraic-data-types

Return an infinite tree consisting of only nodes in Haskell


Given the following simple Tree

 data Tree = 
    Leaf
  | Node Tree Tree
  deriving (Eq, Show)

is there a way to return an infinite amount of nodes (a Tree with just Nodes, no leaves) using recursion?

So far I only know how to return data types such as Boolean and Integer. How do I start about returning a Tree ?


Solution

  • infiniteTree :: Tree
    infiniteTree = Node infiniteTree infiniteTree