[clean-list] order of parameters of "fwrites"

Pieter Koopman pieter at cs.ru.nl
Thu Oct 13 09:19:36 MEST 2005


Hi,

At 01:56 12-10-2005, lethevert wrote:
>In StdEnv Library, these functions are defined.
>
>fwritec         :: !Char !*File -> *File
>fwritei         :: !Int !*File -> *File
>fwriter         :: !Real !*File -> *File
>fwrites         :: !{#Char} !*File -> *File
>
>But why parameters are in this order?

It is (next to) impossible to determine an optimal order of arguments for 
functions. The chosen order is convenient to write definitions like:

endl :: (*File -> *File)
endl = fwrites "\n"

helloWorld :: (*File -> *File)
helloWorld = fwrites "\n" o fwrites "World!" o fwrites " " o fwrites "Hello"

>Recently I found it's useful to write like below;
>
>printSomeStringList :: *File [String] -> *File
>printSomeStringList f lst
>     = foldl (\f s = fwrites s f) f lst

Since arguments are often in the other order as needed in the current 
application, StdEnv provides flip to reverse arguments. It is defined as

flip f a b :== f b a

using this your printSomeStringList can be defined as

printSomeStringList :: (*File -> *([String] -> *File))
printSomeStringList = foldl (flip fwrites)

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.

I don't want to claim that the order of arguments of fwrites or the 
priority of <<< is optimal, for any choice there will be examples where it 
works fine and examples where it is inconvenient.
In general there must be very strong arguments to change such things in the 
library since it can stop existing programs to work correctly.

Have fun,

Pieter Koopman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.science.ru.nl/pipermail/clean-list/attachments/20051013/f2a383ba/attachment.html


More information about the clean-list mailing list