MyNixOS website logo
Description

Left and right actions, semidirect products and torsors.

lr-acts

Haskell Hackage BSD3 License

Features

  • Left and right actions of
    • sets
    • semigroup
    • monoids
    • groups
  • Semidirect product
  • Group torsors
  • Cyclic actions
  • Generated actions

Fine-grained class hierarchy

Left and right actions with a fine-grained class hierarchy for action properties. For left actions, here are the provided classes :

class LAct               -- Set action
 => LActSg               -- Semigroup action
     => LActMn           -- Monoid action
          => LTorsor     -- Torsor
 => LActDistrib          -- Distributive action
 => LActNeutral          -- Neutral preserving action
 => LActGen              -- Action generated by a set
     => LActCyclic       -- Cyclic action (generated by a single element)

Derive most of you action instances

The acting type is always the second parameter. Use this with DerivingVia language extension to derive action instances :

import Data.Act
import Data.Semigroup

newtype Seconds = Seconds Float
newtype Duration = Duration Seconds
  deriving (Semigroup, Monoid) via (Sum Float)

  deriving (LAct Seconds, RAct Seconds) via (ActSelf' (Sum Float))
  -- derives LAct Second  Duration

  deriving (LAct [Seconds], RAct [Seconds]) via (ActMap (ActSelf' (Sum Float)))
   -- derives LAct [Second] Duration

newtype Durations = Durations [Duration]
  deriving (LAct Seconds, RAct Seconds) via (ActFold [Duration])
  -- derives LAct Second Durations

ghci> Duration 2 `lact` Seconds 3
Seconds 5.0

ghci> Duration 2 `lact` [Seconds 3, Seconds 4]
[Seconds 5.0,Seconds 6.0]

ghci> [Duration 2, Duration 3] `lact` Seconds 4
[Seconds 5.0,Seconds 6.0]

ghci> Durations [Duration 2, Duration 3] `lact` Seconds 4
Seconds 9.0

Semidirect products

This fine-grained hierarchy allows to check for associativity and existence of neutral elements using semidirect products.

>>> import Data.Semigroup
>>> LSemidirect (Sum 1) (Product 2) <> LSemidirect (Sum (3 :: Int)) (Product (4 :: Int))
LSemidirect {lactee = Sum {getSum = 7}, lactor = Product {getProduct = 8}}

GHC will complain when using a semigroup action that is not distributive :

>>> LSemidirect (Sum 1) (Sum 2) <> LSemidirect (Sum (3 :: Int)) (Sum (4 :: Int))
No instance for `LActDistrib (Sum Int) (Sum Int)'
  arising from a use of `<>'

Comparison with other action libraries

Here is a list of action libraries on hackage :

In comparison with these libraries, lr-actsis the only library that :

  • Implements right actions
  • Implements cyclic actions and generated actions
  • Ensures the associativity and the neutrality of mempty in semidirect products
  • Proposes several newtypes for deriving instances (note that acts proposes a deriving mechanism, but centered around the actee type, not the actor type as in this library)

The main drawback of providing right actions and checking properties for semidirect products is that the number of instances can quickly be overwhelming. It can be a lot of boiler plate to declare them all, especially when the acting semigroup is commutative.

Metadata

Version

0.0.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows