nikita-volkov / refined

Refinement types with static checking
http://hackage.haskell.org/package/refined
MIT License
183 stars 31 forks source link

`ToJSON`, `FromJSON`, `Arbitrary` #30

Closed i-am-tom closed 5 years ago

i-am-tom commented 5 years ago

Hey!

Firstly, thanks for this library - it's wonderful! We've been using it at work for a number of things, and I was wondering how you'd feel about some extra instances being added. The first two are pretty straightforward, I think:

instance (FromJSON a, Predicate p a)
    => FromJSON (Refined p a) where
  parseJSON = refineFail <=< parseJSON

instance (ToJSON a, Predicate p a)
    => ToJSON (Refined p a) where
  toJSON = toJSON . unrefine

The third is a little more tricky - obviously it would have to involve the refinement predicate - but I'm willing to implement these if you'd be interested in a PR?

Thanks!

chessai commented 5 years ago

Hi,

thanks for your interest in this library. It makes me happy that someone other than me is actually using this for applications in their workplace.

Anyway, to answer your question, for ToJSON/FromJSON instances - I would most certainly welcome those. As for Arbitrary, I'll have to think about it. Would you mind having them in separate PRs?

chessai commented 5 years ago

some thoughts:

1 - this will unavoidable introduce internal orphan instances (refineFail/unrefine/Predicate, etc. exist outside of the module where Refined is defined)

2 - we can probably depend on the these package again, since the reason we avoided it is null now that we're bringing in aeson/QuickCheck

chessai commented 5 years ago

see https://github.com/nikita-volkov/refined/pull/31

i-am-tom commented 5 years ago

Oh wow! Sorry, I've just arrived home from work - this is incredible! Thank you so much :D

/cc @alpacaaa @danieljharvey @fmsbeekmans

chessai commented 5 years ago

version 0.4 is now on hackage, docs building. should be on stackage soon