Imported from chap7.
imported from chap7/. and added type signatures.
imported from chap7/. and slightly modified to supress warnings.
start writing...