Yuichi Tsuchimoto writes:
> > Or look at o's and flippo's types:
> >
> > (.) :: ((a -> b) -> (c -> a)) -> (c -> b)
> > flip (.) :: ((a -> b) -> (b -> c)) -> (a -> c)
> >
> > Surely the second one is much cooler!
>
> Yes, indeed!
>
> Then, the question is why we write
> result = function operand1 operand2
> instead of
> operand1 operand2 function = result
As a question of notation, I think the difference is that you use the
diagrammatic notation (flip (.)) when you want to emphasize the process of
computing something (buzzword, "imperative"). If you read left-to-right then
you can see each stage of a transformation, in the order which it "logically"
occurs. On the other hand, the (.)-style notation emphasizes the declarative
viewpoint since, again reading left-to-right, you start with what you want
and refine down to what you're starting with.
In category theory one often writes commutative arrow diagrams to express
systems of equations. If you use the diagrammatic notation, it can be simpler
to follow paths in the diagram because, by convention, one prefers right- and
down-pointing arrows over left- or up-pointing ones.
If Haskell 98 had user-definable infix type expressions (and <- wasn't part of
the syntax already), you could define the transpose of (->)
type b <- a = a -> b
and then write the signature for (.) as follows:
(c <- a) <- (c <- b) <- (b <- a)
Using <- in type signatures has the advantage that the first thing you see in
a signature is what is produced, rather than what is necessary to produce,
which is sometimes what you want when you have a set of algebraic functions
like John Hughes' pretty-printing library:
text :: Doc <- String
(<+>) :: Doc <- Doc <- Doc
However it does not work so nicely in Haskell since by convention we curry
everything, so the order of arguments is also reversed. If we used uncurried
functions more often the signature for cons
cons :: List a <- List a <- a
would be more intuitive:
cons :: List a <- (a, List a)
(Incidentally, I think Roland Backhouse made this argument, i.e., that we
should prefer (<-) to (->), although he was working with a relational calculus
rather than a functional one.)
--
Frank Atanassow, Dept. of Computer Science, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-1012, Fax +31 (030) 251-3791