## Halgebra 2.0

This week’s assignment is to update your computer algebra solver from Homework #3 to use GADTs to eliminate the need for `error`. This is done by adding a new Step 0 to the procedure that you followed in Homework #3: convert the `Equation` to the new `LEquation` type that allows only linear equations. The type is declared in the `LArith` module I have provided.

Here are the relevant modules:

The bundle of modules includes a `Main` module. This is not part of the assignment, but using it, you can say `ghc Main` at the command-line, and GHC will build an executable `Main` for you that you can use to solve equations.

If it’s helpful, the solution to the last Halgebra assignment is on Moodle.

## Portfolio guidelines

Here is the breakdown of the functions you have been asked to write for your type-level portfolio:

• Functions that work straightforwardly on `Vec` (`and`, `or`, `any`, `map`, `unzip`, `insert`, `sort`, `foldl`, `foldr`, `scanl`, `scanr`, `mapAccumL`, `mapAccumR`): 13

• Functions that are partial on lists but can be made total on `Vec`s (`last`, `uncons`, `foldl1`, `foldr1`, `scanl1`, `scanr1`): 6

• Functions that require some type families or other type-level twists (`init`, `stripPrefix`): 2

• Functions that require interacting with singletons (`null`, `length`, `take`, `drop`, `replicate`, `splitAt`): 6

• Proofs of reasonable difficulty (commutativity of `+`, associativity of `+`): 2

• Proofs of unreasonable difficulty (commutativity of `*`): 1

• `VecList` functions of reasonable difficulty (`intersperse`): 1

• `VecList` functions of unreasonable difficulty (`inits`, `tails`, `intercalate`, `subsequences`, `permutations`, `transpose`): 6

• `EVec` functions (`concatMap`, `unfoldr`, `takeWhile`, `dropWhile`, `dropWhileEnd`, `filter`, `nub`, `delete`, `(\\)`, `union`, `intersect`): 11

• `Fin` functions (`(!!)`, `elemIndex`, `elemIndices`, `findIndex`, `findIndices`): 5

• Functions for which you need to write your own GADT (`span`, `break`, `partition`, `group`): 4

• The Halgebra solver: one big problem.

This adds up to:

• 46 functions of reasonable difficulty (1 pt each)
• 4 where you have to write a GADT (2 pts each)
• 7 of unreasonable difficulty (5 pts each)
• and Halgebra (10 pts)

The total here is 99 points, but the goal isn’t to get to 100. Throwing out the unreasonable problems gives us 64. Arriving at a power of 2 at this point is auspicious. (It certainly wasn’t planned!) Here are the point values and how much, roughly, they are worth on the 4.0-point scale:

• 50+ pts: 4.0
• 40+ pts, including at least 1 custom-GADT question or Halgebra: 3.7
• 40+ pts, otherwise: 3.3
• 35+ pts: 3.0
• 30+ pts: 2.7
• 25+ pts: 2.3
• 20+ pts: 2.0

As always, do let me know if you have any questions.