Held: Friday, April 17, 1998
+------------+
+--->| Program |>---+
| +------------+ |
| |
| 1. Ok | 3. What is my user's home directory?
| 2. Read "hello" | 2. Read the first line of "fred"
| 3. /home/rebelsky | 1. Open file "fred"
| |
| +------------+ |
+---<| OS |<---+
+------------+
[Response] -> [Request].
data Request = ReadFile String | WriteFIle String String | AppendFile String String | ReadBinFile String | DeleteFile String | StatusFile String | ReadChan String | AppendChan String String | ReadBinChan String | AppendBinChan String Bin | StatusChan String | Echo Bool | GetArgs | GetProgName | GetEnv String | SetEnv String String
data Response = Success | Str String | StrList [String] | Bn Bin | Failure IOError
main function of type
[Request] -> [Response], have it generate one or more
requests, and use the responses to those requests to get/produce more
information.
main resps = [ GetEnv "Home", printhome (head resps) ] printhome (Str home) = AppendChan stdout ("My home is" ++ home) printhome (Failure x) = AppendChan stdout "Couldn't find the home"
main resps =
[
AppendChan stdout "Hi there, what is your name?",
ReadChan stdin,
greet (head (tail resps))
]
greet (Str name) =
AppendChan stdout ("Hi there " ++ name)
greet (Failure x) =
AppendChan stdout "Hmmm ... something is very wrong"
main (resp : resps) = [ ... ]
writeFile :: Name -> String -> FailCont -> SuccCont -> Dialogue getEnv :: Name -> FailCont -> StrCont -> Dialogue appendChan :: Name -> FailCont -> SuccCont -> Dialogue done :: Dialogue type Dialogue = [Response] -> [Request] type FailCont = IOError -> Dialogue type SuccCont = Dialogue type StrCont = String -> Dialogue
getEnv "Home" exit (\home ->
appendChan "stdout" ("my home is " ++ home) exit
done
appendChan chan str fail succ resps =
(AppendChan chan str) :
(checkandcontinute fail succ (head resps) (tail resps)
checkandcontinue :: FailCont -> SuccCont -> Response -> Dialogue
checkandcontinue fail succ Success resps = succ resps
checkandcontinue fail succ (Failure msg) = fail msg resps
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Thu May 7 20:29:43 1998.
This page generated on Thu May 7 20:34:47 1998 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu