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

后端 未结 4 1640
北荒
北荒 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:31

    The information in LYAH is old. The release notes for GHC 7.4.1 say that:

    The Num class no longer has Eq or Show superclasses.

    You will need to write,

    foo :: (Num x, Show x) => x -> String
    

    (In fact, the foo you wrote doesn't require Num x, so you can omit that to avoid an unnecessary constraint.)

提交回复
热议问题