how to read function type signatures in Haskell? -
this question has answer here:
- what => symbol mean in haskell? 4 answers
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
Post a Comment