CS 541 Lecture -*- Outline -*- * Input/Output in functional languages reference: Hudak's computing survey paper ** the problem input and output seem to be side effects? *** how to have a reactive system? prompt, read, prompt, read, compute, output, read,... *** race conditions lead to nondeterminism? e.g., reading input from two terminals... => loss of referential transparency? e.g., programs that communicate with each other while running in parallel [ merge ] ____> [ O. S. ] ______> [ split ] ^ ^ | | | |_________ [ prog 1 ] <_________| | | | | . | | . | | . | |______________ [ prog n ] <____________| how does a program receive a list of responses before it has generated any requests? ** solution: lazy evaluation *** stream model program is a function stream of responses -> stream of requests e.g., request: read or write a file response: contents of file, acks, errors *** continuation model pass success continuation and failure continuation as arguments to read and write requests --------------- (writeFile fname s1 exit (readFile fname exit (lambda (s2) ...))) --------------- can translate continuation model into stream model