Type signature needs a type that isn't exported by the library

我只是一个虾纸丫 提交于 2019-12-08 16:51:12

问题


So I was using the aeson library, and thought it would be very useful to have the following function:

v .:! f = liftM (fromMaybe mempty) (v .:? f)

When I ask GHCi for the type, I get:

(.:!)
  :: (Monoid r, FromJSON r) =>
     Object
     -> T.Text -> aeson-0.7.0.6:Data.Aeson.Types.Internal.Parser r

However, Parser itself is not actually exported by either Data.Aeson or Data.Aeson.Types. Am I forced to not have a type signature for the function I have defined?

Alternatively, if anyone knows a better way of accomplishing what I am trying to do, I would be interested in your suggestions.


回答1:


At present it's entirely possible in Haskell to write code that would have an inferred type that you can't write yourself because of unexported symbols. There was a discussion about this on the Haskell libraries mailing list in April 2014 where no firm conclusion was reached but the general sense was to keep the current behaviour.

However the general rule is that if a language extension would be needed to write the type signature that would be inferred, then you need to enable that extension even if you don't include the signature explicitly.



来源:https://stackoverflow.com/questions/24683433/type-signature-needs-a-type-that-isnt-exported-by-the-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!