Popularity
1.8
Stable
Activity
2.4
Declining
2
1
0

Monthly Downloads: 37
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Tags: Algebra     Math     Groups    
Add another 'groups' Package

README

groups-generic

Extends the groups library with functionality for deriving Group instances using generics:

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia   #-}

module Example where

-- base
import Data.Semigroup
  ( Sum(..), Product(..) )
import GHC.Generics
  ( Generic )

-- generic-data
import Generic.Data
  ( GenericProduct(..) )

-- groups
import Data.Group
  ( Group(..) )

-- groups-generic
import Data.Group.Generics
  ( ) -- imports generic instances

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

data Point2D a = Point2D !a !a
  deriving stock Generic
newtype Vector2D a = Vector2D { tip :: Point2D a }
  deriving ( Semigroup, Monoid, Group )
    via GenericProduct ( Point2D ( Sum a ) )

data MyRecord
  = MyRecord
  { field1 :: Sum Double
  , field2 :: Product Double
  , field3 :: ( Sum Int, Sum Int )
  }
  deriving stock Generic
  deriving ( Semigroup, Monoid, Group )
    via GenericProduct MyRecord