Haskell why does “Num x” require “Show x”?

后端 未结 4 1644
北荒
北荒 2020-12-20 13:00

Recently I took a look at Haskell, using LYAH.

I was messing around with type classes and wrote this quick test function:

foo :: (Num x) => x ->         


        
4条回答
  •  我在风中等你
    2020-12-20 13:13

    Haskell, both 98 and 2010 both require all instances of Num to also be instances on Show and Eq. This is largely an accident of history.

    GHC, the most popular Haskell compiler, diverges from the standard here without requiring any pragma. This was done to allow applicative functors to be instances of Num and enjoy the benefits of overloaded syntax.

提交回复
热议问题