1 / 6

More Inductive Types

More Inductive Types. Last Lecture. You can figure out "insert sort" yourself If you follow the recipe, carefully Recipe tells you: Think about base case Think about recursive case (and what to do with result of recursive call) Make a wish-list (e.g. "insert"), and repeat!

edie
Télécharger la présentation

More Inductive Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. More Inductive Types

  2. Last Lecture • You can figure out "insert sort" yourself • If you follow the recipe, carefully • Recipe tells you: • Think about base case • Think about recursive case (and what to do with result of recursive call) • Make a wish-list (e.g. "insert"), and repeat! • Remember this for current homework

  3. Today's Lecture • A short-hand for lists • Another inductive type: trees!

  4. List Shorthands • (cons 1 (cons 2 (cons 3 empty))) • = (list 123) • (cons (cons 1 (cons 2 (cons 3 empty))) empty) • = (list (list 1 2 3)) • (cons (list 1 2) (list 3 4)) • = (list (list 1 2) 3 4)

  5. A Type for Family Trees ; A family-tree-node (short: ftn) is either ; - empty; or ; - (make-child f m na da ec) ; where f and m are ftns, na ; and ec are symbols, and da is a ; number.

  6. Blue-eyed Ancestor ; blue-eyed-ancestor? : ftn  ->  boolean ; to determine whether ; a-ftree contains a child ; structure with 'blue in the ; eyes field

More Related