[Haskell] line-based interactive program

Wolfgang Jeltsch wolfgang at jeltsch.net
Thu Jul 14 07:38:41 EDT 2005


Am Donnerstag, 14. Juli 2005 13:17 schrieben Sie:
> [...]

> > > where readEntireFile reads the entire file and returns it as a string.
> > > I can imagine several results: [a,a], [a,b], [a,_|_], [_|_,_|_], _|_.
> >
> >I decided to distinguish between read-only I/O and write-permitted I/O. 
> > If readEntireFile is declared as read-only I/O (which would be sensible)
> > then the above code would return ['a','a'] since multiple read-only
> > actions are allowed at the same time.
>
> ['a','a'] is a good result in case of multiple readers. But how do you
> distinguish between read-only I/O and write-permitted I/O? In your example
>
> you introduced:
> >     readChar :: FileIO Char
> >     writeChar :: Char -> FileIO ()
>
> Both belong to the FileIO monad. This also relates to the question at the
> bottom of the previous e-mail.

FileIO was the type from a previous approach where I didn't intend to 
distinguish between write-permitted and read-only I/O.  The read-only thing 
which I mentioned later in my mail was an enhancement to this approach where 
write-permitted and read-only actions use different types.

> [...]

> Here you introduce a FileReadIO monad. Is this the way you intend to
> distinguish between read-only actions and write-permitted actions? That
> seems okay.

Yes, FileReadIO denotes read-only actions whereas write-permitted actions are 
denoted by a different monad.

> Minor detail: you use readChar :: FileIO Char within FileReadIO monad. That
> won't type check.

In the advanced approach, readChar would have type FileReadIO Char.

> [...]

Best wishes,
Wolfgang Jeltsch


More information about the Haskell mailing list