Last active
May 5, 2025 21:39
-
-
Save OlaoluwaM/2cdc93cfeab5f0beb357e7a2dba5708d to your computer and use it in GitHub Desktop.
row type HasCodec instance attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Necessary Language extensions | |
import Autodocodec (HasCodec (codec), bimapCodec, (.=)) | |
import Autodocodec qualified as Auto | |
import Control.Lens | |
import Data.Row | |
import Data.Row.Records () | |
import Data.Row.Records qualified as Rec | |
import Data.Text qualified as T | |
import GHC.OverloadedLabels (IsLabel (fromLabel)) | |
import Data.Generics.Labels | |
instance forall r. (AllUniqueLabels r, Forall r HasCodec, Rec.Modify "l" (r .! "l") r ~ r) => HasCodec (Rec r) where | |
codec = | |
Auto.object "" $ Rec.fromLabelsA @HasCodec @(Auto.Codec Object (Rec r)) @r bor | |
where | |
bor :: (KnownSymbol l, HasCodec a, v ~ a) => Label l -> Auto.Codec Object (Rec r) a | |
bor l = Auto.requiredFieldWith' (T.pack $ show l) codec Auto..= (\v -> (v ^. #l) :: a) |
Author
OlaoluwaM
commented
May 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment