some-dict-of 0.1.0.1 → 0.1.0.2
raw patch · 3 files changed
+75/−10 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- changelog.md +4/−0
- some-dict-of.cabal +1/−1
- src/SomeDictOf.hs +70/−9
changelog.md view
@@ -1,3 +1,7 @@+# 0.1.0.2++- Fix docs+ # 0.1.0.1 - Fix lower bound on `base` and Haddock for lambdas
some-dict-of.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: some-dict-of-version: 0.1.0.1+version: 0.1.0.2 synopsis: Carry evidence of constraints around description: Please see the README on GitHub at <https://github.com/parsonsmatt/some-dict-of#readme> category: Constraints
src/SomeDictOf.hs view
@@ -26,20 +26,47 @@ -- -- The alias @'SomeDict' clazz@ uses 'Proxy' for the datatype index. This means -- that the wrapper is a @'Proxy' :: 'Proxy' a@, and you know that the type--- @a@ has an instance of @clazz a@. We can construct a value+-- @a@ has an instance of @clazz a@. The 'SomeDictOf' type does not actually+-- *carry* any values of this type. --+-- That is not to say that we *necessarily* won't have a value - consider+-- @'SomeDictOf' 'Identity'@, which actually does hold a value. We can use this+-- to make an existential 'Show' wrapper.+-- -- @--- showSomeDict :: SomeDictOf Identity Show+-- showSomeDict :: 'SomeDictOf' 'Identity' 'Show' -- showSomeDict =--- SomeDict (Identity 3 :: Identity Int)+-- 'SomeDictOf' ('Identity' 3 :: 'Identity' 'Int') -- @ ----- A value of @'SomeDict' 'Show'@ contains 'Proxy' value. When you pattern--- match on the 'SomeDict', you know that the given @'Proxy' :: 'Proxy' a@--- has an instance of 'Show'.+-- We can happily have a @['SomeDictOf' 'Identity' 'Show']@, or a @Map String+-- ('SomeDictOf' 'Identity' 'Show)@, or similar. ----- For the most part, this isn't useful,+-- Constructing them is easy enough. Consuming them can be a bit trickier. Let's+-- look at a @'SomeDict' 'Monoid'@. --+-- @+-- monoid :: 'SomeDictOf' 'Proxy' 'Monoid'+-- monoid =+-- 'SomeDictOf' ('Proxy' :: 'Proxy' 'Data.Text.Text')+-- @+--+-- All we know about this is that it's carrying a datatype with a 'Monoid'+-- instance. We'll case-match on the value, and then in the case branch, we'll+-- have evidence that (whatever the underlying type is) that it has a 'Monoid'+-- instance.+--+-- We'll repackage the value, but instead of using 'Proxy', we'll stuff 'mempty'+-- into 'Identity'.+--+-- @+-- useMonoid :: 'SomeDictOf' 'Proxy' 'Monoid' -> 'SomeDictOf' 'Identity' 'Monoid'+-- useMonoid someDictOfProxy =+-- case someDictOfProxy of+-- SomeDictOf (Proxy :: Proxy a) ->+-- SomeDictOf (Identity (mempty :: a))+-- @+-- -- @since 0.1.0.0 data SomeDictOf (f :: k -> Type) (c :: k -> Constraint) where SomeDictOf :: c a => f a -> SomeDictOf f c@@ -49,6 +76,40 @@ -- value, we can summon these up whenever we have an instance of the type in -- question. --+-- This is useful when you have a type class that specifies some *static*+-- behavior that is useful, or a type class that can provide means of+-- creating/retrieving/working with data. Consider the @PersistEntity@ class+-- from the @persistent@ database library. An instance of that class can be used+-- to get the @EntityDef@ that describes how the type interacts with the+-- database, or you can even @selectList@ and grab all entities out of the+-- database.+--+-- @+-- someEntity :: 'SomeDict' PersistEntity+-- someEntity = someDict \@User+-- @+--+-- With this value, we can now extract the @EntityDef@:+--+-- @+-- someEntityDef :: EntityDef+-- someEntityDef =+-- case someEntity of+-- SomeDictOf (Proxy :: Proxy a) ->+-- entityDef (Proxy :: Proxy a)+-- @+--+-- We can also load all the rows out of the database.+--+-- @+-- verifyRowsCanLoad :: SqlPersistT IO ()+-- verifyRowsCanLoad =+-- case someEntity of+-- SomeDictOf (Proxy :: Proxy a) -> do+-- rows <- selectList [] [] :: SqlPersistT IO [Entity a]+-- mapM_ (print . entityKey) rows+-- @+-- -- @since 0.1.0.0 type SomeDict = SomeDictOf Proxy @@ -59,10 +120,10 @@ -- -- @ -- showDict :: SomeDict Show--- showDict = someDict @Int+-- showDict = someDict \@Int -- -- entityDict :: SomeDict PersistEntity--- entityDict = someDict @User+-- entityDict = someDict \@User -- @ -- -- @since 0.1.0.0