Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haskell

ghc

aeson

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.

like image 848
Emil Avatar asked Jul 10 '14 18:07

Emil


1 Answers

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.

like image 157
GS - Apologise to Monica Avatar answered Nov 19 '22 17:11

GS - Apologise to Monica