Type Signatures in Haskell -



Type Signatures in Haskell -

my question regarding type signatures.

the next code complies:

data vector = vector a deriving (show) vmult :: (num a) => vector -> -> vector (vector j k) `vmult` m = vector (i*m) (j*m) (k*m)

however, not understand why substituting above type signature (on line number 2) next does not work:

vmult :: (num a) => vector -> num -> vector

my understanding since m of type num (eg. number 8), , since i, j, k num well, there should no problems computing vector (i*m) (j*m) (k*m).

kindly right understanding.

num a isn't type @ all

num type class, if num a means a number type, then

vmult :: (num a) => vector -> -> vector

means "as long a number type, vmult takes vector of as , single a , returns vector of as."

that means vmult can work like vmult :: vector int -> int -> vector int or vmult :: vector double -> double -> vector double. notice each type replacing as in original single number type.

num on it's own doesn't create sense

num on own mean "is number type", if function had type signature

vmult :: (num a) => vector -> num -> vector

it read "as long a number type, vmult takes vector of as , number type , returns vector of as." it's ungrammatical in english language same it's error in haskell.

it's saying "give me butter , has sharp edge" instead of "give me butter , knife". type signature worked saying "find can spread (call k), , give me butter , k."

facts aren't types

you can't utilize num a instead of a vector -> num -> vector a because can't set assertion need noun: "give me key ring , keys made of metal can give new key ring".

haskell

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -