> > 2. I would first like to come back to the type signature
> >
> > f :: a -> b
> >
> > I can say the type of f is a -> b , isn't it?
>
> Well, people often do say that, but it is a little sloppy; if you want
> to be precise, it is more correct to say that the type of `f' is
> `forall a,b . a -> b'.
>
> > But a and b are both variables. Question
> >
> > can I replace the General type b by the type c -> d ?
>
> In general that transformation does not preserve type-correctness.
> Changing `b' to `c -> d' in the type signature might
> change a type-correct program into an ill-typed one.
>
> For example, if the program contains
>
> foo :: Int -> Int
> foo x = f x
>
> then changing the type signature of `f' to `f :: a -> c -> d'
> would mean that the previously type-correct call to `f' here
> would now become a type error.
I would rather say that the programmer has not looked well at the definition of f;
e.g. if f was defined as
f :: a -> a
f x = x
then
foo :: Int -> Int
foo x = f x
gives no problem and
foo1 :: (Int -> Int) -> (Int -> Int)
foo1 x = f x
shouldn't give a problem too, should it?
It is clear that the type a -> a is completely different from the type a -> b : you
can never go with substution from a -> a to a -> b
but the reverse is possible.
Also if f was defined as
f :: a -> b
f x = x
wouldn't the typechecker complain?
Friendly
Jan Brosius