More type design questions

Konrad Hinsen hinsen@cnrs-orleans.fr
Tue, 19 Aug 2003 12:31:08 +0200


On Monday 18 August 2003 22:24, Remi Turk wrote:

> Would this suffice?
=2E..

I guess so - it looks like what Brandon proposed, up to cosmetic differen=
ces.

Still, those cosmetic differences give me the chance to ask another quest=
ion.

> instance Functor Vector where
>     fmap f (Vector x y z)
>                     =3D Vector (f x) (f y) (f z)

Under what conditions would Haskell programmers make some type an instanc=
e of=20
Functor? Whenever it could possibly be done (i.e. whenever fmap makes sen=
se)?=20
Or just when fmap would be used frequently for some type?

In this case, I can't think of any other use for fmap than defining scala=
r=20
multiplication. There is no other vector operation that applies some=20
operation to each element and returns another vector. Would it be conside=
red=20
"better" to define fmap nevertheless, and then use it in scalar=20
multiplication, or would one prefer to define the mapping operation into =
its=20
only application?

Konrad.