A Tour of Go in Haskell

GitHub Language
Exercise: Equivalent Binary Trees (2/2)
  1. Implement walk.
  2. Test walk.
  3. A function newTree :: Int -> IO Tree randomly constructs a binary tree which has k,2k,3k,..,10k as elements, where k::Int is the argument. You can walk on a new binary tree as:

    t1 <- newTree 1
    async $ walk t1 ch

    If you read and print values from the channel, 1,2,3,..,10 should be appeared.

  4. Implement same using walk.
  5. Test same.
    t1<-newTree 1; t1'<-newTree 1; sae t1 t1' should return True, and
    t1<-newTree 1; t2<-newTree 2; same t1 t2 should return False.

Actual implementations of Tree and newTree is here. An example solution is here.

(Off topic: A Tour of Go emphasizes that we can write this algorithm easiar than other languages because Go has channels. In Haskell, pure lists make it easier rather than channels. A sample code on the right side also shows a list implementation.)

< 8 / 11 >