Download A screen editor written in the Miranda1 functional programming

Transcript
4.
Modification to Thompson's Combinators
A fundamental feature in any editor is the ability to save files! This means that
the interact type must be changed as files cannot be saved if the output type
is [[char]]. In Miranda the value of an expression is a list of “system
messages”. The type sys_message has definition (where file == [char]):
sys_message ==
Stdout [char] | Stderr [char] | ToFile file [char] |
Closefile file | Appendfile file | System [char] |
Exit num
Miranda silently converts anything that is not sys_message to this form (so
most of the time we do not need to know about sys_message). Example:
Miranda 2+5
7
The 7 is the result of the conversion: [Stdout (show(2+5))].
To allow the usage of the ToFile component we must change the output
type to sys_message. The interact type becomes:
interact * ** == ([[char]], *)
([[char]], **, [sys_message])
All the Thompson functions have been changed (where necessary) to reflect
this. Thus write becomes:
write :: [char] -> interact * *
write outstring (in,st)
= (in,st,[Stdout outstring])
12