Elixir Exercises

Author: Tyler M. Masthay

CPS 499-03: Emerging Languages, Spring 2017

  1. Modify the program Counter2.ex so that a private member variable currCount is printed and modified.

  2. Implement a module for a binary tree closure that is purely functional. Use the following representation: a leaf node is a tuple of the form {:leaf, val} where val is the value associated with this tree and an internal node is of the form {:internal, left, right} where left and right are the associated subtrees. Ensure that polymorphics trees are supported. For example, the tree {:internal, {:leaf, 1}, {:leaf, fn(x) -> x}} should be supported within the module.

  3. Use the binary tree from problem 2 to implement the foldl and foldr functions from the Haskell programming language.