Datatypes, Trees, and Type classes
> module Main where
> -- see http://www.seas.upenn.edu/~cis5520/current/hw/hw02/Main.html
> -- DO NOT MODIFY THIS FILEThis homework covers material from Datatypes and Classes. There are four problems.
1. Problem - XML processing
See Play for an exercise involving tree
transformation.
2. Problem - Return of the Data Munging Kata
See Kata for a problem that asks you to design
a type-class based library that can be used to the Kata problem
from the first homework assignment.
3. Problem - Sorted lists and type abstraction
See SortedList for a demonstration of type
abstraction in Haskell and practice with the type classes Semigroup
and Monoid.
4. Problem - MergeSort for foldable data structures
See MergeSort for practice with the Foldable
type class.
In this homework assignment, we rely on the HUnit testing framework to define and
execute unit tests. These import commands bring the tests for each problem into
scope.
> import Play(testXML)
> import Kata(testParseEventChar, testSoccer)
> import SortedList(testListMonoid, testSortedList,
> testMinimum, testNumDistinct, testCount)
> import MergeSort(testSortedFromList,testSortedFromList',
> testSumOfProducts,testCrispy, testDivide, testDivideList)> import Test.HUnit (runTestTT, Test(TestList))We can then define a function that will run all of the tests in all modules. In the
terminal, you can use the command stack run to run all tests.
> main :: IO ()
> main = do
> putStrLn "Runing test cases for HW02 ..."
> _ <- runTestTT $ TestList [testXML]
> _ <- runTestTT $ TestList [testParseEventChar, testSoccer]
> _ <- runTestTT $ TestList [testListMonoid, testSortedList, testMinimum, testNumDistinct, testCount]
> _ <- runTestTT $ TestList [testSortedFromList, testSortedFromList', testSumOfProducts,
> testCrispy, testDivide, testDivideList]
> return ()You can also use doctests to run individual test cases in your editor.
> -- >>> runTestTT testXML
> -- Counts {cases = 1, tried = 1, errors = 0, failures = 0}> -- >>> runTestTT testParseEventChar
> -- Counts {cases = 3, tried = 3, errors = 0, failures = 0}
CIS 5520: Advanced Programming