Why sum x y is of type (Num a) => a -> a -> a in Haskell?

后端 未结 5 1562
臣服心动
臣服心动 2021-01-02 07:39

I\'ve been reading about Haskell and I\'m having a hard time understanding how function definitions are handled in this language.

Let\'s say I\'m defining a su

5条回答
  •  旧巷少年郎
    2021-01-02 08:03

    The Haskell documentation isn't too clear about it, but (Num a) => means that the function works for all cases where a is a Num or derives from it (therefore is a number).

    Also see: http://www.cse.unsw.edu.au/~en1000/haskell/inbuilt.html

提交回复
热议问题