1 / 8

Section 4

Section 4. CSE 341 – Patrick Larson. Mutual Recursion. What if we need function f to call g, a nd function g to call f?. Mutual Recursion. Does this work? 1 fun f x = 5 fun g y = 2 ... 6 ... 3 g y 7 f x 4 ... 8 . Mutual Recursion.

angelo
Télécharger la présentation

Section 4

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. Section 4 CSE 341 – Patrick Larson

  2. Mutual Recursion What if we need function f to call g, and function g to call f?

  3. Mutual Recursion Does this work? 1fun f x = 5 fun g y = 2 ... 6 ... 3 g y 7 f x 4... 8 ...

  4. Mutual Recursion We can employ higher order functions for a work around. fun earlier (f,x) = … f y … … fun later x = … earlier(later,y)

  5. Mutual Recursion But ML gives us special syntax for this 1fun f x = 5 and g y = 2 ... 6 ... 3 g y 7 f x 4 ... 8 ...

  6. Modules Remember that signatures are good both for organization and management and for maintaining invariants

  7. Modules - Invariants • Ordering of operations • e.g. insert, then query • Data kept in good state • e.g. fractions in lowest terms • Policies followed • e.g. don't allow shipping request without purchase order • Sensitive information hidden • e.g. force authentication for api use

  8. Currying and Higher Order Functions Questions?

More Related