Skip to content

Instantly share code, notes, and snippets.

@chessai
Created March 26, 2018 12:37
Show Gist options
  • Save chessai/14ca32e8d0331e0c625fa1169bde50a6 to your computer and use it in GitHub Desktop.
Save chessai/14ca32e8d0331e0c625fa1169bde50a6 to your computer and use it in GitHub Desktop.
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
class Semiring a where
zero :: a
one :: a
plus :: a -> a -> a
times :: a -> a -> a
class SemiringForall (f :: k -> *) where
zeroForall :: f a
oneForall :: f a
plusForall :: f a -> f a -> f a
timesForall :: f a -> f a -> f a
class Semiring1 (f :: * -> *) where
liftZero :: a -> f a
liftOne :: a -> f a
liftPlus :: (a -> a -> a) -> f a -> f a -> f a
liftTimes :: (a -> a -> a) -> f a -> f a -> f a
zero1, one1 :: (Semiring1 f, Semiring a) => f a
zero1 = liftZero zero
one1 = liftOne one
plus1, times1 :: (Semiring1 f, Semiring a) => f a -> f a -> f a
plus1 = liftPlus plus
times1 = liftTimes times
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment