<html>
<body>
Hi,<br><br>
At 01:56 12-10-2005, lethevert wrote:<br>
<blockquote type=cite class=cite cite="">In StdEnv Library, these
functions are defined.<br><br>
fwritec<x-tab> </x-tab><x-tab>
</x-tab>:: !Char !*File
-> *File<br>
fwritei<x-tab> </x-tab><x-tab>
</x-tab>:: !Int !*File
-> *File<br>
fwriter<x-tab> </x-tab><x-tab>
</x-tab>:: !Real !*File
-> *File<br>
fwrites<x-tab> </x-tab><x-tab>
</x-tab>:: !{#Char}
!*File -> *File<br><br>
But why parameters are in this order?</blockquote><br>
It is (next to) impossible to determine an optimal order of arguments for
functions. The chosen order is convenient to write definitions
like:<br><br>
<tt>endl :: (*File -> *File)<br>
endl = fwrites "\n"<br><br>
helloWorld :: (*File -> *File)<br>
helloWorld = fwrites "\n" o fwrites "World!" o
fwrites " " o fwrites "Hello" <br><br>
</tt><blockquote type=cite class=cite cite="">Recently I found it's
useful to write like below;<br><br>
printSomeStringList :: *File [String] -> *File<br>
printSomeStringList f lst<br>
= foldl (\f s = fwrites s f) f lst</blockquote><br>
Since arguments are often in the other order as needed in the current
application, <tt>StdEnv </tt>provides <tt>flip </tt>to reverse arguments.
It is defined as<br><br>
<tt>flip f a b :== f b a<br><br>
</tt>using this your <tt>printSomeStringList</tt> can be defined
as<br><br>
<tt>printSomeStringList :: (*File -> *([String] -> *File))<br>
printSomeStringList = foldl (flip fwrites)<br><br>
</tt>A similar problem exists with the priority of infix operators: it is
(next to) impossible to determine priorities such that you never have to
write parenthesis.<br><br>
I don't want to claim that the order of arguments of <tt>fwrites</tt> or
the priority of <tt><<<</tt> is optimal, for any choice there
will be examples where it works fine and examples where it is
inconvenient.<br>
In general there must be very strong arguments to change such things in
the library since it can stop existing programs to work
correctly.<br><br>
Have fun,<br><br>
Pieter Koopman <br>
</body>
</html>