named-records 0.3.3 → 0.4
raw patch · 7 files changed
+119/−73 lines, 7 filesdep +binaryPVP ok
version bump matches the API change (PVP)
Dependencies added: binary
API changes (from Hackage documentation)
+ Data.NamedRecord: instance [overlap ok] (Binary v, Binary b) => Binary (v :+ b)
+ Data.NamedRecord: instance [overlap ok] Binary v => Binary (n := v)
+ Data.NamedRecord: names :: Names' a => a
+ Data.NamedRecord: upd :: Property o n v => o -> n := (v -> v) -> o
Files
- Sample.hs +0/−44
- Sample2.hs +0/−22
- examples/Sample.hs +44/−0
- examples/Sample2.hs +22/−0
- examples/Signature.hs +21/−0
- named-records.cabal +12/−4
- src/Data/NamedRecord.hs +20/−3
− Sample.hs
@@ -1,44 +0,0 @@-{-# LANGUAGE Haskell2010- , TemplateHaskell- , FlexibleContexts- , TypeOperators- , Trustworthy- #-}--- {-# OPTIONS -ddump-splices #-}--module Main where--import Data.NamedRecord-import Data.Word---import Sample2--name "firstName"-name "lastName"-name "loginName"-name "password"---record "User"- `extends` __Person- `extends` __Account-- `has` "id" := ''Word64- `has` "emailAddress" := ''String---julian = newPerson `set` firstName := "Julian"- `set` lastName := "Fleischer"--alexander = newUser `set` firstName := "Alexander"- `set` lastName := "Carnicero"- `set` loginName := "alexander.carnicero"--displayName obj = (obj `get` firstName) ++ " " ++ (obj `get` lastName)--something :: (Property o $(nameT "firstName") String,- Property o $(nameT "lastName") String)- => o -> String-something = displayName-
− Sample2.hs
@@ -1,22 +0,0 @@-{-# LANGUAGE Haskell2010, TemplateHaskell #-}--module Sample2 where--import Data.NamedRecord-import Data.Word---record "Account"- `has` "id" := ''Word64-- `has` "loginName" := ''String- `has` "password" := ''String---record "Person"- `has` "id" := ''Word64-- `has` "firstName" := ''String- `has` "lastName" := ''String--
+ examples/Sample.hs view
@@ -0,0 +1,44 @@+{-# LANGUAGE Haskell2010+ , TemplateHaskell+ , FlexibleContexts+ , TypeOperators+ , Trustworthy+ #-}+-- {-# OPTIONS -ddump-splices #-}++module Main where++import Data.NamedRecord+import Data.Word+++import Sample2++name "firstName"+name "lastName"+name "loginName"+name "password"+++record "User"+ `extends` __Person+ `extends` __Account++ `has` "id" := ''Word64+ `has` "emailAddress" := ''String+++julian = newPerson `set` firstName := "Julian"+ `set` lastName := "Fleischer"++alexander = newUser `set` firstName := "Alexander"+ `set` lastName := "Carnicero"+ `set` loginName := "alexander.carnicero"++displayName obj = (obj `get` firstName) ++ " " ++ (obj `get` lastName)++something :: (Property o $(nameT "firstName") String,+ Property o $(nameT "lastName") String)+ => o -> String+something = displayName+
+ examples/Sample2.hs view
@@ -0,0 +1,22 @@+{-# LANGUAGE Haskell2010, TemplateHaskell #-}++module Sample2 where++import Data.NamedRecord+import Data.Word+++record "Account"+ `has` "id" := ''Word64++ `has` "loginName" := ''String+ `has` "password" := ''String+++record "Person"+ `has` "id" := ''Word64++ `has` "firstName" := ''String+ `has` "lastName" := ''String++
+ examples/Signature.hs view
@@ -0,0 +1,21 @@+{-# LANGUAGE Haskell2010, TemplateHaskell, FlexibleContexts #-}++import Data.NamedRecord++names "firstName" "lastName"++record "User"+ `has` "accountId" := ''Integer+ `has` "firstName" := ''String+ `has` "lastName" := ''String++record "Person"+ `has` "firstName" := ''String+ `has` "lastName" := ''String+++displayName :: (Property o $(nameT "firstName") String,+ Property o $(nameT "lastName") String)+ => o -> String+displayName obj = (obj `get` firstName) ++ " " ++ (obj `get` lastName)+
named-records.cabal view
@@ -1,5 +1,5 @@ Name: named-records-Version: 0.3.3+Version: 0.4 Synopsis: Flexible records with named fields. Description: Flexible records with named fields. .@@ -25,6 +25,10 @@ . [@v0.3.3@] Pushed requirements for @names-0.3.1@. Updated documentation and samples.+ .+ [@v0.4@] Records can now be serialized by means of+ the @binary@ package. Added @upd@ function.+ . License: MIT License-File: LICENSE@@ -35,8 +39,12 @@ Category: Data, Records Stability: experimental -Extra-Source-Files: Sample.hs, Sample2.hs+Extra-Source-Files:+ examples/Sample.hs,+ examples/Sample2.hs,+ examples/Signature.hs + Source-Repository head type: darcs location: hub.darcs.net:names@@ -44,8 +52,7 @@ Source-Repository head type: darcs location: hub.darcs.net:names- tag: v0.3.3-+ tag: v0.4 Library@@ -53,6 +60,7 @@ Build-Depends: base >= 4 && < 5, names == 0.3.1,+ binary >= 0.5, template-haskell >= 2.7 Hs-Source-Dirs: src
src/Data/NamedRecord.hs view
@@ -144,7 +144,7 @@ -} module Data.NamedRecord (- Property (get, set),+ Property (get, set, upd), New (new), add, @@ -165,16 +165,19 @@ -- ** Names -- For convenience, this module re-exports name TH name functions.- name, nameT, nameV+ name, nameT, nameV, names ) where +import Control.Applicative import Control.Monad+import Data.Binary hiding (get)+import qualified Data.Binary as B import Data.Data import Data.Function (on) import Data.List import qualified Data.Name-import Data.Name (name, nameT, nameV)+import Data.Name (name, nameT, nameV, names) import Data.Typeable import Language.Haskell.TH import Language.Haskell.TH.Quote@@ -200,22 +203,36 @@ class Property o n v | o n -> v where get :: o -> n -> v set :: o -> n := v -> o+ upd :: o -> n := (v -> v) -> o infixl 1 `set` infixl 1 `get`+infixl 1 `upd` instance Property (n := v) n v where get (_ := v) _ = v set _ v = v+ upd (_ := v) (n := f) = (n := f v) instance Property ((n := v) :+ b) n v where get (a :+ b) n = get a n set (a :+ b) p = (set a p) :+ b+ upd (a :+ b) f = (upd a f) :+ b instance Property b n v => Property (a :+ b) n v where get (a :+ b) n = get b n set (a :+ b) p = a :+ (set b p)+ upd (a :+ b) f = a :+ (upd b f)+++instance Binary v => Binary (n := v) where+ put (_ := v) = put v+ get = (_type :=) <$> B.get++instance (Binary v, Binary b) => Binary (v :+ b) where+ put (v :+ b) = put v >> put b+ get = liftM2 (:+) B.get B.get class New o where