How to override Show instance of some basic types in Haskell?

后端 未结 4 1406
太阳男子
太阳男子 2021-01-18 05:19

I\'m writting some programs in Haskell, dealing with a lot of basic types like Word32/Word64 etc.. I use ghci to test the functions frequently, see the results in terminal.<

4条回答
  •  遥遥无期
    2021-01-18 06:15

    That would be abusing the Show instance. It's not really meant for formatting. If you want to show something in hexadecimal, just use a function to do the conversion. For example, you can use showHex from Numeric to make a small helper like this:

    > import Numeric
    Numeric> let hex x = showHex x ""
    Numeric> hex 123456
    "1e240"
    

提交回复
热议问题