cs510 FSC Staged Computation Assignment #7 Winter 2005 assigned Tuesday Feb. 22, 2005 due in class Thursday March 3, 2005 Recall the "printf" function from C. "printf" takes a format string (which contains both text and formatting directives) and a list of arguments, and prints the list according to the formatting directives. It also splices in the text (which is not formatting directives) in the format string into the output. For example, if the integer variable "count"=5, and the string variable "message"="an odd number", then printf("Today's count %d is %s",count,message) prints the string: "Today's count 5 is an odd number" Formatting directives begin with an "%" and are followed by single character from the following table: % - a literal percent character. No argument is required. c - the argument is treated as an integer, and presented as the character with that ASCII value. f - the argument is treated as a float, and presented as a floating-point number. s - the argument is treated as and presented as a string. d - the argument is treated as an integer, and presented as a (signed) decimal number. In MetaML we can simulate this as follows data Directive = Percent | C | F | S | D | Text of String data Value = Char of char | Float of real | String of string | Int of int printf:: [Directive] -> [Value] -> string Using these functions we can cast the example from C above as printf [Text "Today's count ",D,Text " is ",S] [Int 5,String "an odd number"] 1) Give MetaML definition for the function "printf" with the type printf:: [Directive] -> [Value] -> string . Use the function error::string -> a to report errors, such as too many arguments, and a directive which doesn't match its actual argument. Be sure and handle all possible errors. 2) Now stage the function so it has the folling type: printf2 :: [Directive] -> <[Value]> -> 3) Now stage the function so it has the folling type: printf3 :: [Directive] -> <[Value] -> string> 4) Now stage the function so it has the folling type: printf4 :: [Directive] -> [] -> 5) Consider the partially staged "Value" type. data Value2 = Char2 of | Float2 of | String2 of | Int2 of Now stage the function so it has the folling type: printf5 :: [Directive] -> [Value2] -> Compare this version with those in parts 2-4. Is there something going on here? Be sure and include sample tests of all your functions.