{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Star
( Star(..)
) where
import Data.Bool (Bool(..))
import Data.Function (id, (.), const)
import Data.Proxy (Proxy(..))
import Data.Semiring
class (Semiring a) => Star a where
#if __GLASGOW_HASKELL__ >= 708
{-# MINIMAL star | aplus #-}
#endif
star :: a -> a
star a = one `plus` aplus a
aplus :: a -> a
aplus a = a `times` star a
instance Star b => Star (a -> b) where
star = (.) star
aplus = (.) aplus
{-# INLINE star #-}
{-# INLINE aplus #-}
instance Star Bool where
star _ = True
aplus = id
{-# INLINE star #-}
{-# INLINE aplus #-}
instance Star () where
star _ = ()
aplus _ = ()
{-# INLINE star #-}
{-# INLINE aplus #-}
instance Star (Proxy a) where
star _ = Proxy
aplus _ = Proxy
{-# INLINE star #-}
{-# INLINE aplus #-}
instance Star Mod2 where
star = const one