这是一个显示问题的小程序:
import Data.Fixed
main = do
print x
where
x :: Pico
x = read "12" -- error: no instance for 'Read Pico'
Run Code Online (Sandbox Code Playgroud)
我在Fixed.hs中看到了库GHC源代码 - 有一个Read实例(复制一些代码):
type Pico = Fixed E12
data E12 = E12
instance HasResolution E12 where
resolution _ = 1000000000000
instance (HasResolution a) => Read (Fixed a) where
readsPrec _ = readsFixed
Run Code Online (Sandbox Code Playgroud)
我的推理有什么问题,为什么编译器没有看到Pico是Read的实例?