| Under consideration for publication in J. Functional Programming 1 FUNCT I ONAL PEARL (2007) | |||||||||||||||
Abstract | |||||||||||||||
| Introduction When I was a student, Simula was one of the languages taught in introductory programming language courses and I vividly remember a sticker one of our instructors had attached to the door of his oce, saying \Simula does it with class". I guess the same holds for Haskell except that Haskell replaces classes by type classes. Armed with singleton types, multiple-parameter type classes, and functional dependencies we reconsider a problem raised and solved by Danvy in a previous pearl (1998). The challenge is to implement a variant of C's printf function, called format below, in a statically typed language. Here is an interactive session that illustrates the problem: Maini :type format (lit "hello world") String Maini format (lit "hello world") "hello world" Maini :type format int Int ! String Maini format int 5 "5" Maini :type format (int ^ lit " is " ^ str) Int ! String ! String Maini format (int ^ lit " is " ^ str) 5 "five" "5 is five": The format directive lit | |||||||||||||||
Publication details | |||||||||||||||
| |||||||||||||||