Skip to content

Modulo Semigroup? #98

@solomon-b

Description

@solomon-b

Would you guys be interested in a PR adding a Semigroup for modular arithmetic?

Something like this:

data Mod (k :: Nat) (f :: * -> *) (a :: *) = Mod (f a)

instance (KnownNat k, Semigroup (f a), Applicative f,  Integral a) => Semigroup (Mod k f a) where
  (<>) (Mod fx) (Mod fy) = Mod $
    mod <$> (fx <> fy) <*> (pure $ fromIntegral $ natVal $ Proxy @k)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions