th-dict-discovery: Automatically discover available dictionaries at compile time.

[ bsd3, language, library ] [ Propose Tags ]

th-dict-discovery is a library to get your hands on the in-scope, concrete instances of a class. The motivating use-case is to generate property tests to automatically prove new instances of a class follow the laws.

This library uses Template Haskell to provide a list of existentialized Dicts for each concrete (entirely monomorphic) instance in scope.

defInstances :: [SomeDict1 Default]
defInstances = $(someDicts ''Default)

These lists can be consumed via withSomeDict1 :: (forall a. c a => Proxy a -> r) -> SomeDict1 c -> r, for example, we can generate hspec tests:

spec :: Spec
spec = describe "each default instance" .
  forM_ defInstances $ withSomeDict1 $ \(_ :: Proxy a) ->
    it "shouldn't be undefined" $
      seq (def @a) True `shouldBe` True

The library also defines up to SomeDict8, with eliminators up to withSomeDict8. These correspond to multi-parameter typeclasses with first-order, potentially polykinded parameters.

The TH function someDicts is smart enough to generate the correct arity of SomeDictN for the class under inspection, but at this time, you're responsible for using the correct withSomeDictN to consume it.

Modules

  • Language
    • Haskell
      • Language.Haskell.Discovery

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0
Change log ChangeLog.md
Dependencies base (>=4.9 && <4.10), constraints, template-haskell [details]
License BSD-3-Clause
Author Sandy Maguire
Maintainer sandy@sandymaguire.me
Category Language
Home page http://github.com/isovector/th-dict-discovery/
Bug tracker http://github.com/isovector/th-dict-discovery/issues
Source repo head: git clone https://github.com/isovector/th-dict-discovery.git
Uploaded by isovector at 2017-12-27T09:54:45Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 779 total (4 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2017-12-27 [all 2 reports]