Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Generically instance #33

Open
Icelandjack opened this issue Nov 16, 2022 · 1 comment
Open

Missing Generically instance #33

Icelandjack opened this issue Nov 16, 2022 · 1 comment

Comments

@Icelandjack
Copy link

Icelandjack commented Nov 16, 2022

Can you add an instance for Generically (base 4.17)?

Older versions are supported with the generically package:

import GHC.Generics.Generically

instance (Generic a, GFlatEncode (Rep a), GFlatDecode (Rep a), GFlatSize (Rep a)) => Flat (Generically a) where
  encode :: Generically a -> Encoding
  encode (Generically a) = gencode (from a)

  decode :: Get (Generically a)
  decode = Generically . to <$> gget

  size :: Generically a -> NumBits -> NumBits
  size (Generically !x) !n = gsize n (from x)

This gives a type that represents the generic Flat definition. You can derive Flat via it:

{-# Language DeriveGeneric #-}
{-# Language DerivingVia   #-}

import Flat
import GHC.Generics

data Direction = North | South | Center | East | West
  deriving stock Generic
  deriving Flat via Generically Direction 

Users can modify the generic behaviour by defining wrappers, via Generically (Override .. '[A `As` A', B `As` B', ..]).

@tittoassini
Copy link
Collaborator

Thanks, I shall look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants