Prelude classes comparison between base and linear-base

March 16, 2022 ยท View on GitHub

Class in base (non-linear)

Equivalent class(es) in linear-base

Data.Eq (Eq), Prelude (Eq)

class Eq a where
  (==) :: a -> a -> Bool
  (/=) :: a -> a -> Bool

Data.Eq.Linear (Eq), Prelude.Linear (Eq)

class Eq a where
  (==) :: a %1 -> a %1 -> Bool
  (/=) :: a %1 -> a %1 -> Bool

Data.Ord (Ord), Prelude (Ord)

class Eq a => Ord a where
  compare :: a -> a -> Ordering
  (<) :: a -> a -> Bool
  (<=) :: a -> a -> Bool
  (>) :: a -> a -> Bool
  (>=) :: a -> a -> Bool
  max :: a -> a -> a
  min :: a -> a -> a

Data.Linear.Ord (Ord), Prelude.Linear (Ord)

class Eq a => Ord a where
  compare :: a %1 -> a %1 -> Ordering
  (<=) :: a %1 -> a %1 -> Bool
  (<) :: a %1 -> a %1 -> Bool
  (>) :: a %1 -> a %1 -> Bool
  (>=) :: a %1 -> a %1 -> Bool

N.B.: min and max are available as functions (not methods) in the same module.

GHC.Enum (Enum), Prelude (Enum)

class Enum a where
  succ :: a -> a
  pred :: a -> a
  toEnum :: Int -> a
  fromEnum :: a -> Int
  enumFrom :: a -> [a]
  enumFromThen :: a -> a -> [a]
  enumFromTo :: a -> a -> [a]
  enumFromThenTo :: a -> a -> a -> [a]

Prelude (non-linear) version reexported as Prelude.Linear (Enum)

GHC.Bounded (Enum), Prelude (Bounded)

class Bounded a where
  minBound :: a
  maxBound :: a

Prelude (non-linear) version reexported as Prelude.Linear (Bounded)

GHC.Num (Num), Prelude (Num)

class Num a where
  (+) :: a -> a -> a
  (-) :: a -> a -> a
  (*) :: a -> a -> a
  negate :: a -> a
  abs :: a -> a
  signum :: a -> a
  fromInteger :: Integer -> a

Data.Num.Linear (Num), Prelude.Linear (Num)

class Additive a where
  (+) :: a %1 -> a %1 -> a
class Additive a => AddIdentity a where
  zero :: a
class AddIdentity a => AdditiveGroup a where
  negate :: a %1 -> a
  (-) :: a %1 -> a %1 -> a
class Multiplicative a where
  (*) :: a %1 -> a %1 -> a
class Multiplicative a => MultIdentity a where
  one :: a
class (AddIdentity a, MultIdentity a) => Semiring a
class (AdditiveGroup a, Semiring a) => Ring a
class FromInteger a where
  fromInteger :: Prelude.Integer %1 -> a

class (Ring a, FromInteger a) => Num a where
  abs :: a %1 -> a
  signum :: a %1 -> a

GHC.Real (Real), Prelude (Real)

class (Num a, Ord a) => Real a where
  toRational :: a -> Rational

Prelude (non-linear) version reexported as Prelude.Linear (Real)

N.B.: Prelude.Linear (Real) uses non-linear constraints Num and Ord.

GHC.Real (Integral), Prelude (Integral)

class (Real a, Enum a) => Integral a where
  quot :: a -> a -> a
  rem :: a -> a -> a
  div :: a -> a -> a
  mod :: a -> a -> a
  quotRem :: a -> a -> (a, a)
  divMod :: a -> a -> (a, a)
  toInteger :: a -> Integer

Prelude (non-linear) version reexported as Prelude.Linear (Integral)

GHC.Real (Fractional), Prelude (Fractional)

class Num a => Fractional a where
  (/) :: a -> a -> a
  recip :: a -> a
  fromRational :: Rational -> a

Prelude (non-linear) version reexported as Prelude.Linear (Fractional)

GHC.Float (Floating), Prelude (Floating)

class Fractional a => Floating a where
  pi :: a
  exp :: a -> a
  log :: a -> a
  sqrt :: a -> a
  (**) :: a -> a -> a
  logBase :: a -> a -> a
  sin :: a -> a
  cos :: a -> a
  tan :: a -> a
  asin :: a -> a
  acos :: a -> a
  atan :: a -> a
  sinh :: a -> a
  cosh :: a -> a
  tanh :: a -> a
  asinh :: a -> a
  acosh :: a -> a
  atanh :: a -> a
  log1p :: a -> a
  expm1 :: a -> a
  log1pexp :: a -> a
  log1mexp :: a -> a

Prelude (non-linear) version reexported as Prelude.Linear (Floating)

GHC.Real (RealFrac), Prelude (RealFrac)

class (Real a, Fractional a) => RealFrac a where
  properFraction :: Integral b => a -> (b, a)
  truncate :: Integral b => a -> b
  round :: Integral b => a -> b
  ceiling :: Integral b => a -> b
  floor :: Integral b => a -> b

Prelude (non-linear) version reexported as Prelude.Linear (RealFrac)

GHC.Float (RealFloat), Prelude (Float)

class (RealFrac a, Floating a) => RealFloat a where
  floatRadix :: a -> Integer
  floatDigits :: a -> Int
  floatRange :: a -> (Int, Int)
  decodeFloat :: a -> (Integer, Int)
  encodeFloat :: Integer -> Int -> a
  exponent :: a -> Int
  significand :: a -> a
  scaleFloat :: Int -> a -> a
  isNaN :: a -> Bool
  isInfinite :: a -> Bool
  isDenormalized :: a -> Bool
  isNegativeZero :: a -> Bool
  isIEEE :: a -> Bool
  atan2 :: a -> a -> a

Prelude (non-linear) version reexported as Prelude.Linear (RealFloat)

Data.Semigroup (Semigroup), Prelude (Semigroup)

class Semigroup a where
  (<>) :: a -> a -> a
  sconcat :: NonEmpty a -> a
  stimes :: Integral b => b -> a -> a

Data.Monoid.Linear (Semigroup), Prelude.Linear (Semigroup)

class Semigroup a where
  (<>) :: a %1 -> a %1 -> a

N.B.: Linear versions of sconcat and stimes are not available.

Data.Moinoid (Monoid), Prelude (Monoid)

class Semigroup a => Monoid a where
  mempty :: a
  mappend :: a -> a -> a
  mconcat :: [a] -> a

Data.Monoid.Linear (Monoid), Prelude.Linear (Monoid)

class Semigroup a => Monoid a where
  mempty :: a

N.B.: mconcat and mappend are available as functions (not methods) in the same module.

Data.Functor (Functor), Prelude (Functor)

class Functor f where
  fmap :: (a -> b) -> f a -> f b
  (<$) :: a -> f b -> f a

Data Functor

Data.Functor.Linear (Functor)

class Data.Functor f where
  fmap :: (a %1 -> b) -> f a %1 -> f b

N.B.: (<$) is available as a function (not method) in the same module.

Control Functor

Control.Functor.Linear (Functor)

class Data.Functor f => Control.Functor f where
  fmap :: (a %1 -> b) %1 -> f a %1 -> f b

N.B.: (<$) is available as a function (not method) in the same module.

Control.Applicative (Applicative), Prelude (Applicative)

class Functor f => Applicative f where
  pure :: a -> f a
  (<*>) :: f (a -> b) -> f a -> f b
  liftA2 :: (a -> b -> c) -> f a -> f b -> f c
  (*>) :: f a -> f b -> f b
  (<*) :: f a -> f b -> f a

Data Applicative

Data.Functor.Linear (Applicative)

class Data.Functor f => Data.Applicative f where
  pure :: a -> f a
  (<*>) :: f (a %1 -> b) %1 -> f a %1 -> f b
  liftA2 :: (a %1 -> b %1 -> c) -> f a %1 -> f b %1 -> f c

N.B.: a linear Data variant of (<*) is available as a function (not method) in Prelude.Linear with the following signature:

(<*) :: (Data.Applicative f, Consumable b) => f a %1 -> f b %1 -> f a

(*>) is not available though.

Control Applicative

Control.Functor.Linear (Applicative)

class (Data.Applicative f, Control.Functor f) => Control.Applicative f where
  pure :: a %1 -> f a
  (<*>) :: f (a %1 -> b) %1 -> f a %1 -> f b
  liftA2 :: (a %1 -> b %1 -> c) %1 -> f a %1 -> f b %1 -> f c

N.B.: linear Control variants of (<*) and (*>) are not available.

Control.Monad (Monad), Prelude (Monad)

class Applicative m => Monad m where
  (>>=) :: forall a b. m a -> (a -> m b) -> m b
  (>>) :: forall a b. m a -> m b -> m b
  return :: a -> m a

Control.Functor.Linear (Monad)

class Control.Applicative m => Monad m where
  (>>=) :: m a %1 -> (a %1 -> m b) %1 -> m b
  (>>) :: m () %1 -> m a %1 -> m a

N.B.: return is available as a function (not method) in the same module.

Control.Monad.Fail (MonadFail), Prelude (MonadFail)

class Monad m => MonadFail m where
  fail :: String -> m a

Control.Functor.Linear (MonadFail)

class Monad m => MonadFail m where
  fail :: String -> m a

Data.Foldable (Foldable), Prelude (Foldable)

class Foldable t where
  fold :: Monoid m => t m -> m
  foldMap :: Monoid m => (a -> m) -> t a -> m
  foldMap' :: Monoid m => (a -> m) -> t a -> m
  foldr :: (a -> b -> b) -> b -> t a -> b
  foldr' :: (a -> b -> b) -> b -> t a -> b
  foldl :: (b -> a -> b) -> b -> t a -> b
  foldl' :: (b -> a -> b) -> b -> t a -> b
  foldr1 :: (a -> a -> a) -> t a -> a
  foldl1 :: (a -> a -> a) -> t a -> a
  toList :: t a -> [a]
  null :: t a -> Bool
  length :: t a -> Int
  elem :: Eq a => a -> t a -> Bool
  maximum :: forall a. Ord a => t a -> a
  minimum :: forall a. Ord a => t a -> a
  sum :: Num a => t a -> a
  product :: Num a => t a -> a

No linear counterpart available at the moment, but individual fold functions can be found in Data.List.Linear

Data.Traversable (Traversable), Prelude (Traversable)

class (Functor t, Foldable t) => Traversable t where
  traverse :: Applicative f => (a -> f b) -> t a -> f (t b)
  sequenceA :: Applicative f => t (f a) -> f (t a)
  mapM :: Monad m => (a -> m b) -> t a -> m (t b)
  sequence :: Monad m => t (m a) -> m (t a)

Data.Functor.Linear (Traversable)

class Data.Functor t => Traversable t where
  traverse :: Control.Applicative f => (a %1 -> f b) -> t a %1 -> f (t b)
  sequence :: Control.Applicative f => t (f a) %1 -> f (t a)

N.B.: sequenceA and mapM are available as functions (not methods) in the same module.

GHC.Show (Show), Prelude (Show)

class Show a where
  showsPrec :: Int -> a -> ShowS
  show :: a -> String
  showList :: [a] -> ShowS

Prelude (non-linear) version reexported as Prelude.Linear (Show)

GHC.Read (Read), Prelude (Read)

class Read a where
  readsPrec :: Int -> ReadS a
  readList :: ReadS [a]

Prelude (non-linear) version reexported as Prelude.Linear (Read)

No non-linear counterpart available.

Data.Unrestricted.Linear (Consumable), Prelude.Linear (Consumable)

class Consumable a where
  consume :: a %1 -> ()

No non-linear counterpart available.

Data.Unrestricted.Linear (Dupable), Prelude.Linear (Dupable)

class Consumable a => Dupable a where
  dupR :: a %1 -> Replicator a
  dup2 :: a %1 -> (a, a)

No non-linear counterpart available.

Data.Unrestricted.Linear (Movable), Prelude.Linear (Movable)

class Dupable a => Movable a where
  move :: a %1 -> Ur a