CSE 134B- Midterm Exam Guide - Comprehensive Notes for the exam ( 41 pages long!)

303 views41 pages

Document Summary

Trees data tree a = node (tree a) (tree a) | leaf a. Instance show a => show (tree a) where show (leaf a) = show a show (node lt rt) = show lt ++ /\ ++ show rt. Tiny calculator language data expr = addexpr expr expr. Instance show expr where show (constrexpr i) = show i. Show (addexpr e1 e2) = show e1 ++ + ++ show e2. Show (multexpre e1 e2) = show e1 ++ * ++ show e2. Or . use unword haskell function! show (addexpr e1 e2) = unwords [ ( , show e1, ) , + , ( , show e2, ) ] show (mulexpr e1 e2) = unwords [ ( , show e1, ) , * , ( , show e2, ) ] Checking equality checks only syntactically! (constexpr i1) == (constexpr i2) = i1 == i2 this is just dumb, lazy evaluation. We need to do an instance where we eval the expressions!

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers