GHCi ignores type signature

后端 未结 2 620
梦谈多话
梦谈多话 2021-02-12 13:16
Prelude> let myprint = putStrLn . show
Prelude> :t myprint
myprint :: () -> IO ()

OK, nothing too unusual here. Just GHCi type defaulting rule

2条回答
  •  醉话见心
    2021-02-12 14:03

    We can do the following, with monomorphism restriction on:

    >let myprint :: Show x => x -> IO (); myprint = putStrLn . show
    >:t myprint
    myprint :: Show x => x -> IO ()
    

    This is not the same as let myprint = putStrLn . show :: Show x => x -> IO (). In the former case we have a binding with a type signature, in the latter case we a have a let binding with a type annotation inside the right hand side. Monomorphism checks top-level type signatures, but not local annotations.

提交回复
热议问题