[m-dev.] Here's an idea.
Fergus Henderson
fjh at cs.mu.oz.au
Fri Sep 5 21:47:17 AEST 1997
Tyson Richard DOWD, you wrote:
> Fergus Henderson wrote:
> >
> > It would work OK if you use import_module rather than use_module,
> > but then you have the problem that [1,2,3] is ambiguous.
>
> This probably isn't a huge problem, but it's not very nice.
Hmm, I suspect it would probably break type inference in a lot of cases.
And I think type inference is likely to save more keystrokes.
However, I'm not really sure exactly how it would interact with
type inference, maybe we should try it out and get some experience with
it.
> > However, this still doesn't solve one of the main problems of formatted
> > I/O, namely extensibility. I think that if we are going to extend the
> > current formatted I/O support, we should look for a solution using type
> > classes that can provide formatted I/O for values of user-defined types.
>
> Sure, but even a typeclasses based solution would benefit from a neat way
> of writing heterogenous lists. Unless you have in mind another method...
Well, for an extensible version, using a special little language inside the
format string is a bit of a problem, because it is difficult to extend
that language. So instead of
printf("X = %6.3f, S = %20s\n", [f(X), s(S)])
you might write something like
printf("X = %%, S = %%", [f(6, 3, X), s(20, S)])
If most of your format strings contain formatting information like "%6.3f",
then special support for heterogenous lists wouldn't help much.
On the other hand, thinking about it a bit more it is true that most format
strings don't contain that sort of formatting information.
So I guess it is worthwhile trying to optimize the common case.
Hmm. How's this for another idea:
printf([X, S |+ "X = %%, S = %%"])
This one avoids the problem with [1,2,3] being ambiguous.
To make it work, you just need to overload ./2 and +/1:
:- type format_list.
:- func '.'(T, format_list) = format_list.
:- func '+'(string) = format_list.
The '|+' is kinda baroque syntax, though.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list