Skip to content

Missing Generically instance #33

@Icelandjack

Description

@Icelandjack

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', ..]).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions