record-encode 0.2 → 0.2.1
raw patch · 3 files changed
+8/−5 lines, 3 files
Files
- README.md +1/−1
- record-encode.cabal +1/−1
- src/Data/Record/Encode.hs +6/−3
README.md view
@@ -23,7 +23,7 @@ ``` > encodeOneHot B- [0,1,0]+ OH {oDim = 3, oIx = 1} ```
record-encode.cabal view
@@ -1,5 +1,5 @@ name: record-encode-version: 0.2+version: 0.2.1 synopsis: Generic encoding of records description: Generic encoding of records. It currently provides a single, polymorphic function to encode sum types (i.e. categorical variables) as one-hot vectors. homepage: https://github.com/ocramz/record-encode
src/Data/Record/Encode.hs view
@@ -37,9 +37,12 @@ -data X a = A | B a | C | D | E | F deriving G.Generic-instance Generic (X a)+-- data X a = A | B a | C | D | E | F deriving G.Generic+-- instance Generic (X a) +data X = A | B | C deriving (G.Generic)+instance Generic X+ -- | Constraints necessary to 'encodeOneHot' a value. -- -- NB: 'GVariants' is an internal typeclass, and this constraint is automatically satisfied if the type is an instance of 'G.Generic'@@ -59,7 +62,7 @@ -- >>> instance SOP.Generic X -- -- >>> encodeOneHot B--- [0,1,0]+-- OH {oDim = 3, oIx = 1} encodeOneHot :: forall a . G a => a -> OneHot encodeOneHot x = OH len i where len = fromIntegral $ gnconstructors (Proxy :: Proxy a)