is identity the only polymorphic function without typeclasses?

Jon Cast jcast@ou.edu
Mon, 03 Mar 2003 22:57:01 -0600


Andrew J Bromage <ajb@spamcop.net> wrote:
> G'day.

> On Mon, Mar 03, 2003 at 11:49:29AM +0200, Cagdas Ozgenc wrote:

> > Yes, I thought about these too. Do you find these functions
> > practically useful? Can you give an example where I can utilize
> > these functions?

> Functions like this are useful for plugging into higher-order
> functions to tailor them for your specific needs.

> Here's an artificial example:

> 	length = sum . map (const 1)

Incidentally, here's another artificial example:

> indices = zipWith const [0..]

This can be used to define scanl, incidentally:

> scanl f z xn = [foldl f z (take i xn) | i <- indices (undefined:xn)]

(where the undefined: just reflects the fact that we want one more
element than xn has).

Jon Cast