packages feed

binrep-instances (empty) → 0.1.0

raw patch · 9 files changed

+165/−0 lines, 9 filesdep +basedep +binrepdep +strongweak

Dependencies added: base, binrep, strongweak

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+## 0.1.0 (2025-03-11)+Initial release.++  * extracted from binrep+  * strongweak instances
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2022-2025 Ben Orchard (@raehik) <thefirstmuffinman@gmail.com>++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,13 @@+# binrep-instances+Orphan instances for binrep.++binrep mostly cares about standalone data types that are exclusively used with+its type classes. However, my strongweak library lends itself to working+together with binrep. But it requires a couple of orphan instances, and adds+some non-orphan but out-of-place instances to binrep (`WeakenN` is an "ignore"+layer, which otherwise doesn't fit in binrep). It's kind of like an extension.++Such orphan instances are pulled out into this library.++## License+Provided under the MIT license. See `LICENSE` for license text.
+ binrep-instances.cabal view
@@ -0,0 +1,54 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.36.1.+--+-- see: https://github.com/sol/hpack++name:           binrep-instances+version:        0.1.0+synopsis:       Orphan instances for binrep+description:    Please see README.md.+category:       Data, Serialization+homepage:       https://github.com/raehik/binrep-instances#readme+bug-reports:    https://github.com/raehik/binrep-instances/issues+author:         Ben Orchard+maintainer:     Ben Orchard <thefirstmuffinman@gmail.com>+license:        MIT+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    CHANGELOG.md++source-repository head+  type: git+  location: https://github.com/raehik/binrep-instances++library+  exposed-modules:+      Binrep.Instances.Strongweak+      Binrep.Instances.Strongweak.SWChain+      Binrep.Instances.Strongweak.Type.Magic+      Binrep.Instances.Strongweak.Type.Thin+      Binrep.Instances.Strongweak.Util.ByteOrder+  other-modules:+      Paths_binrep_instances+  hs-source-dirs:+      src+  default-extensions:+      LambdaCase+      NoStarIsType+      DerivingVia+      DeriveAnyClass+      GADTs+      RoleAnnotations+      DefaultSignatures+      TypeFamilies+      DataKinds+      MagicHash+  ghc-options: -fhide-source-paths -Wall+  build-depends:+      base >=4.18 && <5+    , binrep >=1.1.0 && <1.2+    , strongweak >=0.11.0 && <0.12+  default-language: GHC2021
+ src/Binrep/Instances/Strongweak.hs view
@@ -0,0 +1,8 @@+-- | Pull in all strongweak binrep instances, for base classes and types.++module Binrep.Instances.Strongweak () where++import Binrep.Instances.Strongweak.SWChain()+import Binrep.Instances.Strongweak.Type.Magic()+import Binrep.Instances.Strongweak.Type.Thin()+import Binrep.Instances.Strongweak.Util.ByteOrder()
+ src/Binrep/Instances/Strongweak/SWChain.hs view
@@ -0,0 +1,23 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++{- | binrep instances for 'SWChain' where @Cls a => Cls ('SWChain' n a)@.++'SW' and 'SWChain' can help define binreppable data types plus an "easy to work+with" representation in one fell swoop. 'SWChain' is a meaningless newtype only+there to help strongweak do its work (without having to write instances+manually). So here, we define a bunch of recursive instances that use the inner+type.+-}++module Binrep.Instances.Strongweak.SWChain where++import Binrep+import Strongweak+import Data.Kind ( type Type )++deriving via (a :: Type) instance IsCBLen  a => IsCBLen  (SWChain n a)+deriving via (a :: Type) instance    BLen  a =>    BLen  (SWChain n a)+deriving via (a :: Type) instance     Put  a =>     Put  (SWChain n a)+deriving via (a :: Type) instance     PutC a =>     PutC (SWChain n a)+deriving via (a :: Type) instance     Get  a =>     Get  (SWChain n a)+deriving via (a :: Type) instance     GetC a =>     GetC (SWChain n a)
+ src/Binrep/Instances/Strongweak/Type/Magic.hs view
@@ -0,0 +1,16 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++-- | Weaken @'Magic'@ to '()', to separate weak forms from binrep-land.++module Binrep.Instances.Strongweak.Type.Magic where++import Binrep.Type.Magic+import Strongweak++-- | Weaken a @'Magic' a@ to the unit '()'.+instance Weaken   (Magic a) where+    type Weakened (Magic a) = ()+    weaken Magic = ()++-- | Strengthen the unit '()' to some @'Magic' a@.+instance Strengthen (Magic a) where strengthen () = Right Magic
+ src/Binrep/Instances/Strongweak/Type/Thin.hs view
@@ -0,0 +1,10 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE UndecidableInstances #-} -- required for SWCoercibly++module Binrep.Instances.Strongweak.Type.Thin where++import Binrep.Type.Thin+import Strongweak++deriving via SWCoercibly a instance     Weaken (Thin a)+deriving via SWCoercibly a instance Strengthen (Thin a)
+ src/Binrep/Instances/Strongweak/Util/ByteOrder.hs view
@@ -0,0 +1,16 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++-- | Weaken @'ByteOrdered' end a@ to @a@.+--+-- These are in raehik's custom @primitive@ modules, and strongweak wouldn't+-- touch them anyway unless they were in base or close (simply too specific).++module Binrep.Instances.Strongweak.Util.ByteOrder where++import Binrep.Util.ByteOrder+import Strongweak++-- note that we don't need UndecidableInstances here!+-- happens when defining an orphan instance on a non-package type+deriving via SWCoercibly a instance     Weaken (ByteOrdered end a)+deriving via SWCoercibly a instance Strengthen (ByteOrdered end a)