问题
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