[m-rev.] deduplicating getopt modules

Peter Wang novalazy at gmail.com
Sat Sep 19 13:20:14 AEST 2020


On Sat, 19 Sep 2020 13:09:44 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> 
> 2020-09-19 12:46 GMT+10:00 "Peter Wang" <novalazy at gmail.com>:
> >> Or are you proposing that process_options take a pair of arguments
> >> of type T, which *may* be I/O states at some call sites but not others, and that
> >> the type class constraint be on T? 
> > 
> > Something like:
> > 
> >     :- typeclass file_special_handler(T, S) <= (S -> T) where [ ... ].
> > 
> >     :- instance file_special_handler(io.input_stream, io.state).
> > 
> >     :- type no_file_special_handle.
> >     :- type no_file_special.
> >     :- instance file_special_handler(no_file_special_handle, no_file_special).
> > 
> >     :- pred process_options(option_ops(OptionType)::in(option_ops),
> > 	list(string)::in, list(string)::out,
> > 	maybe_option_table(OptionType)::out, S::di, S::uo) is det
> > 	<= file_handler(S, T).
> 
> I don't understand what the T argument of the typeclass is intended to be for.
> The only operation the typeclass needs is "given a filename, return either
> a string that is the contents of the file it names, or an error description",
> which does not need any type beyond the I/O state.

You're right. I was thinking T, the file handle, was required because
the typeclass would have separate methods to open the file, read from
the file handle, and close the file handle.

Peter


More information about the reviews mailing list