how to read function type signatures in Haskell? -


this question has answer here:

given function adds 1 int, can see type signature:

prelude> addone :: int -> int; addone x = x + 1 prelude> :t addone addone :: int -> int 

the signature means addone takes int , returns int. simple enough. instead if define function without specifying type:

prelude> anotheraddone x = x + 1 prelude> :t anotheraddone anotheraddone :: num => -> 

it makes sense dealing num not int whats way read num => -> a? , difference between => , -> here?

anotheraddone :: num => -> 

the => here separates class constraint , type. in example, num a class constraint, consists of class num , type variable a. full signature declares type a num, function anotheraddone has type a -> a.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -