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)
- Host: GitHub
- URL: https://github.com/sheaf/groups-generic
- Owner: sheaf
- Created: 2020-02-14T20:41:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-16T15:00:50.000Z (over 2 years ago)
- Last Synced: 2025-01-31T13:12:10.447Z (over 1 year ago)
- Language: Haskell
- Size: 6.84 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
Awesome Lists containing this project
README
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
```