An open API service indexing awesome lists of open source software.

https://github.com/sheaf/groups-generic

Derive Group instances using generics (Haskell library)
https://github.com/sheaf/groups-generic

Last synced: 8 months ago
JSON representation

Derive Group instances using generics (Haskell library)

Awesome Lists containing this project

README

          

# groups-generic

Extends the [groups](https://hackage.haskell.org/package/groups) library with functionality for deriving `Group` instances using generics:

```haskell
{-# 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
```