Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 1.1.0 (unreleased)
* fix ByteOrdered orphan strongweak instances to follow strongweak pattern --
for original behaviour, use `WeakenN 2 (ByteOrdered end a)`
* update rerefined, strongweak
## 1.1.0 (2025-03-11)
* remove strongweak integration
* to be released in separate package binrep-instances
* update rerefined

## 1.0.0 (2024-10-03)
* fix `NullTerminate` check being inverted (OOPS LOL)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022-2024 Ben Orchard (@raehik) <[email protected]>
Copyright (c) 2022-2025 Ben Orchard (@raehik) <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
14 changes: 14 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# binrep to-dos
## Separate from strongweak
I don't use strongweak here, only write a few useful instances.
I could have a separate package for orphan instances instead.
This would make me much happier about:

* the `WeakenN` instances, which are the only "through" newtype currently
permitted in binrep -- these would be over there
* the `ByteOrdered` orphans -- they would be over there

But I feel comfortable with the `Magic` weakening being here. And strongweak is
a small package. But still...

Yes, I think I should do this. No, I don't think it's very interesting or fun.

## Discrepancy in generic sum interface
In `Get`, I require a `Getter pt`. But in `Put`/`BLen`, you have to pass the
`Putter`/`BLen` manually. I'm not sure which one is correct. Probably `Get`.
Expand Down
5 changes: 1 addition & 4 deletions binrep.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: binrep
version: 1.0.0
version: 1.1.0
synopsis: Encode precise binary representations directly in types
description: Please see README.md.
category: Data, Serialization, Generics
Expand Down Expand Up @@ -100,7 +100,6 @@ library
, ghc-bignum ==1.3.*
, parser-combinators >=1.3.0 && <1.4
, rerefined >=0.8.0 && <0.9
, strongweak >=0.11.0 && <0.12
, text >=2.0 && <2.2
, text-builder-linear >=0.1.3 && <0.2
, type-level-bytestrings >=0.1.0 && <0.3
Expand Down Expand Up @@ -153,7 +152,6 @@ test-suite spec
, parser-combinators >=1.3.0 && <1.4
, quickcheck-instances >=0.3.26 && <0.4
, rerefined >=0.8.0 && <0.9
, strongweak >=0.11.0 && <0.12
, text >=2.0 && <2.2
, text-builder-linear >=0.1.3 && <0.2
, type-level-bytestrings >=0.1.0 && <0.3
Expand Down Expand Up @@ -198,7 +196,6 @@ benchmark bench
, ghc-bignum ==1.3.*
, parser-combinators >=1.3.0 && <1.4
, rerefined >=0.8.0 && <0.9
, strongweak >=0.11.0 && <0.12
, text >=2.0 && <2.2
, text-builder-linear >=0.1.3 && <0.2
, type-level-bytestrings >=0.1.0 && <0.3
Expand Down
82 changes: 17 additions & 65 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
haskell-flake.url = "github:srid/haskell-flake";
rerefined.url = "github:raehik/rerefined";
rerefined.flake = false;
bytezap.url = "github:raehik/bytezap";
bytezap.flake = false;
strongweak.url = "github:raehik/strongweak";
strongweak.flake = false;
};

outputs = inputs:
Expand Down Expand Up @@ -39,34 +33,16 @@

# https://github.com/phadej/defun/pull/5
settings.defun-core.jailbreak = true;

# waiting on nixpkgs update
packages.rerefined.source = inputs.rerefined;
settings.strongweak.broken = false;
packages.strongweak.source = inputs.strongweak;
packages.bytezap.source = inputs.bytezap;
};

haskellProjects.ghc98 = {
basePackages = pkgs.haskell.packages.ghc98;
devShell = defDevShell "ghc98";

# waiting on nixpkgs update
packages.rerefined.source = inputs.rerefined;
settings.strongweak.broken = false;
packages.strongweak.source = inputs.strongweak;
packages.bytezap.source = inputs.bytezap;
};

haskellProjects.ghc96 = {
basePackages = pkgs.haskell.packages.ghc96;
devShell = defDevShell "ghc96";

# waiting on nixpkgs update
packages.rerefined.source = inputs.rerefined;
settings.strongweak.broken = false;
packages.strongweak.source = inputs.strongweak;
packages.bytezap.source = inputs.bytezap;
};
};
};
Expand Down
3 changes: 1 addition & 2 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: binrep
version: 1.0.0
version: 1.1.0
synopsis: Encode precise binary representations directly in types
description: Please see README.md.
extra-source-files:
Expand Down Expand Up @@ -68,7 +68,6 @@ dependencies:
- generic-data-functions ^>= 0.6.0
- generic-type-asserts ^>= 0.3.0
- generic-type-functions ^>= 0.1.0
- strongweak ^>= 0.11.0
- defun-core ^>= 0.1

# core instances
Expand Down
8 changes: 2 additions & 6 deletions src/Binrep/BLen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ import Binrep.Common.Via.Generically.NonSum
import Rerefined.Refine
import Rerefined.Predicate.Logical.And

import Strongweak.WeakenN

-- | Class for types with easily-calculated length in bytes.
--
-- If it appears hard to calculate byte length for a given type (e.g. without
Expand Down Expand Up @@ -130,13 +128,11 @@ deriving via ViaCBLen Word32 instance BLen Word32
deriving via ViaCBLen Int32 instance BLen Int32
deriving via ViaCBLen Word64 instance BLen Word64
deriving via ViaCBLen Int64 instance BLen Int64

-- | Explicitness does not alter length.
deriving via ViaCBLen (ByteOrdered end a)
instance KnownNat (CBLen a) => BLen (ByteOrdered end a)

-- | Unwrap strongweak wrapper.
instance BLen a => BLen (WeakenN n a) where
blen = blen . unWeakenN

--------------------------------------------------------------------------------

-- | DerivingVia wrapper for types which may derive a 'BLen' instance through
Expand Down
10 changes: 2 additions & 8 deletions src/Binrep/CBLen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import Bytezap.Common.Generic ( type GTFoldMapCAddition )

import Binrep.Common.Via.Generically.NonSum

import Strongweak.WeakenN

class IsCBLen a where type CBLen a :: Natural

-- | Deriving via this instance necessitates @UndecidableInstances@.
Expand All @@ -55,12 +53,8 @@ instance IsCBLen Int32 where type CBLen Int32 = 2^2
instance IsCBLen Word64 where type CBLen Word64 = 2^3
instance IsCBLen Int64 where type CBLen Int64 = 2^3

instance IsCBLen a => IsCBLen (ByteOrdered end a) where
type CBLen (ByteOrdered end a) = CBLen a

-- | Unwrap strongweak wrapper.
instance IsCBLen a => IsCBLen (WeakenN n a) where
type CBLen (WeakenN n a) = CBLen a
-- | Endianness does not alter constant length.
deriving via (a :: Type) instance IsCBLen a => IsCBLen (ByteOrdered end a)

-- | Reify a type's constant byte length to the term level.
cblen :: forall a. KnownNat (CBLen a) => Int
Expand Down
4 changes: 4 additions & 0 deletions src/Binrep/Example/Tga.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Binrep.Example.Tga where

{-

{-
import Binrep
import Binrep.Type.Derived.NullTermPadded
Expand All @@ -26,3 +28,5 @@ data ImageType
| RLEColorMapped
| RLETrueColor
| RLEBW

-}
9 changes: 0 additions & 9 deletions src/Binrep/Get.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import Rerefined.Predicate.Logical.And
import Data.Word
import Data.Int
import Data.Void
import Data.Functor.Identity
import Binrep.Common.Via.Generically.NonSum

import Generic.Data.FOnCstr
Expand All @@ -52,8 +51,6 @@ import GHC.Exts ( Proxy# )

import Data.Typeable ( Typeable, TypeRep, typeRep, Proxy(Proxy) )

import Strongweak.WeakenN

type Getter = FP.Parser (ParseError FP.Pos TBL.Builder)

class Get a where
Expand Down Expand Up @@ -222,8 +219,6 @@ instance Get Write where

-}

instance Get a => Get (Identity a) where get = Identity <$> get

-- | Unit type parses nothing.
instance Get () where
{-# INLINE get #-}
Expand Down Expand Up @@ -324,7 +319,3 @@ runGetWith
runGetWith r bs = runGetter (getWith r) bs

-}

-- | Unwrap strongweak wrapper.
instance Get a => Get (WeakenN n a) where
get = WeakenN <$> get
Loading
Loading