class Function ?
Josef Svenningsson
josefs@cs.chalmers.se
Tue, 29 Oct 2002 09:34:03 +0100 (MET)
Hi all,
On Tue, 29 Oct 2002, Johannes Waldmann wrote:
> On Tue, 29 Oct 2002, Lloyd Allison wrote:
>
> > I would like to have a ``class Function'' which has the
> > operators ``$'', ``.'', etc. and *most* particularly ``'',
>
> yes yes yes I want this too.
>
Overloading "blank space" or function application has been one of my
favourite haskell jokes for some time. While I have many times thought
that it would be really cute I think that in practice it would be just
unmanagable. *Every* function composition would be overloaded and we would
end up with *tons* of class constraints like
Function a => (a b c) -> b -> c
It would be slow and the types would be unreadable.
> When presenting definitions in Haskell (to myself, or to students),
> I don't like being forced to decide on the representation of functions
> (be it `actual function', array, list, FiniteMap, whatever) too early.
>
I think this is a non-argument. A good programming style (at least in my
opinion) is to always assume `actual functions' as the representation. You
can always convert bulk type operations later.
An example. Say you have a function foo which takes a map as its first
argument. Just assume the `actual function' respresentation. When a
function bar uses foo but has a different representation of map we just
cast it to a function.
foo :: (key -> value) -> ....
foo = ...
bar = ... foo (\key -> lookup map key) ...
Cheers,
/Josef