Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deriving type step by step

Tags:

haskell

I have a real problem with deriving type and do not understand at all, how to derive type.

I defined a function f with following implementation:

f x y z = x * y * z

the type signature of function f is:

f :: Num c => c -> c -> c -> c

pretty simple, right?

Now, apply f to map and id function and looking at type signature.

First, let's apply map f:

a -> b "The signature of the first argument of map
~    ~
c -> c -> c -> c "The signature of the f function

you can see above, how I separates and get type equality, namely a ~ c and b ~ c -> c -> c.

Then, lets apply id f

a -> a           "The signature of the id
~    ~
c -> c -> c -> c "The signature of the f function

Like I separated above, I would say a ~ c and a ~ c -> c -> c, but this is wrong and I not understand why. I do exactly the sample principle like above. Right would be a ~ c -> c -> c -> c.

Could someone please explain it to me step by step, how deriving type works? I would say, I do understand the concept of deriving type at all.

like image 407
softshipper Avatar asked Aug 07 '17 14:08

softshipper


1 Answers

You actually wrote it yourself in the question:

  • a -> b -- The signature of the first argument of map
  • a -> a -- The signature of id

To compare apples and apples, you need to start with

  • a -> b -- The signature of the first argument of map
  • a -- The signature of the first argument of id
like image 198
leftaroundabout Avatar answered Oct 12 '22 14:10

leftaroundabout