GHCi ignores type signature

后端 未结 2 605
无人共我
无人共我 2021-02-12 13:40
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:17

    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.

提交回复
热议问题