CSE 130 Lecture Notes - Lecture 16: Type Class, Identity Function, Type Safety

48 views4 pages

Document Summary

If (x > 55) { loop forever } Remember: type io a = world -> (a, world) De-sugar getchar :: io char world (char, world) Given a world, give you a char, and a new world with the char in it putchar :: char -> io () char world ((), world) Return :: a io a a world (a, world) Ex: return x w = (x, w) x :: a w :: world. Compose (>>) :: io a io b io b (world -> (a, world)) (world (b, world)) (world (b, world)) (>>) act 1 act 2 world 0 = Let ( _, w 1 ) = act 1 world 0 ( y, w 2 ) = act 2 w 1. Example: return 42 >> putchar a" >> putchar b" //prints a" and b" to the terminal (discards 42) f x = putstrln hello world >> Else return bye bye! f :: string io string f hello = hello .

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
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents