[Haskell-cafe] Type of a function?

Jason Dagit dagit at eecs.oregonstate.edu
Fri Jul 14 19:57:58 EDT 2006


On 7/14/06, Jenny678 <mestor1 at gmx.de> wrote:
>
> Hallo
>
> Can somebody tell me the type of  the following function?
>
> func :: ?????????????
> func f x = (z,y)
>   where (z,y) = f x

Let's try to reason about it.  Let's start with some approximation to
the type of 'func'.

It appears to take two parameters so we'll say,
func :: a -> b -> c

Now we look at the first parameter, f, and see that it can be applied
to x to get a tuple.
f :: b -> (d, e)

Now we can replace the the type variable 'a' with the signature for f.
func :: (b -> (d, e)) -> b -> c

But we also notice that the type (d, e) which is returned by f is also
returned by func.
func :: (b -> (d, e)) -> b -> (d, e)

So there you have it.  That's how you can reason about types. (and
hopefully I didn't make a clerical error...)

HTH,
Jason


More information about the Haskell-Cafe mailing list