-- | A pure specification of getChar and putChar.moduleTest.IOSpec.Teletype(-- * The IOTeletype monadTeletype-- * Pure getChar and putChar,getChar,putChar,putStr,putStrLn,getLine)whereimportPreludehiding(getChar,putChar,putStr,putStrLn,getLine)importControl.Monad(forM_)importTest.IOSpec.TypesimportTest.IOSpec.VirtualMachine-- The 'Teletype' specification.---- | An expression of type 'IOSpec' 'Teletype' @a@ corresponds to an @IO@-- computation that may print to or read from stdout and stdin-- respectively.---- There is a minor caveat here. I assume that stdin and stdout are-- not buffered. This is not the standard behaviour in many Haskell-- compilers.dataTeletypea=GetChar(Char->a)|PutCharCharainstanceFunctorTeletypewherefmapf(GetChartt)=GetChar(f.tt)fmapf(PutCharctt)=PutCharc(ftt)-- | The 'getChar' function can be used to read a character from the-- teletype.getChar::(:<:)Teletypef=>IOSpecfChargetChar=inject(GetCharreturn)-- | The 'getChar' function can be used to print a character to the-- teletype.putChar::(Teletype:<:f)=>Char->IOSpecf()putCharc=inject(PutCharc(return()))instanceExecutableTeletypewherestep(GetCharf)=doc<-readCharreturn(Step(fc))step(PutCharca)=doprintCharcreturn(Stepa)putStr::(Teletype:<:f)=>String->IOSpecf()putStrstr=forM_strputCharputStrLn::(Teletype:<:f)=>String->IOSpecf()putStrLnstr=putStrstr>>putChar'\n'getLine::(Teletype:<:f)=>IOSpecfStringgetLine=doc<-getCharifc=='\n'thenreturn[]elsegetLine>>=\line->return(c:line)