packages feed

antelude-0.1.0: src/Antelude/Internal/TypesClasses.hs

{- |
Module      : Antelude.Internal.TypesClasses
Description : Just contains Antelude's internal base of types and typeclasses.
Maintainer  : dneavesdev@pm.me
-}
module Antelude.Internal.TypesClasses
  ( -- * Types
    -- ** Basics
    -- | Reexport from 'Data.Bool'
    Bool (..)
    -- | Reexport from 'Data.Char'
  , Char
    -- | Reexport from 'Data.String'
  , String
    -- | Reexport from 'Data.Int'
  , Int
    -- | Reexport from 'Prelude'
  , Integer
    -- | Reexport from 'Prelude'
  , Float
    -- | Reexport from 'Prelude'
  , Double
    -- | Reexport from 'Data.Ratio'
  , Rational
    -- | Reexport from 'Data.Word'
  , Word
    -- ** Container-Types
    -- *** List and List-ish
    -- | Reexport from 'Data.List'
  , List
    -- | Reexport from 'Data.List.NonEmpty'
  , NonEmpty (..)
    -- | Reexport from 'Data.Array' of the "array" package
  , Array
    -- *** Formally-Named Tuples
  , Pair
  , Trio
    -- ** External-Package-Types
  , ByteString
  , ByteStringLazy
  , Map
  , MapLazy
  , Text
  , TextLazy
    -- | Reexport from 'Data.Set' of the "containers" package
  , Set
    -- | Reexport from 'Data.Sequence' of the "containers" package
  , Seq
    -- ** Other Important Things
    -- | Reexport from 'Data.Maybe'
  , Maybe (..)
    -- | Reexport from 'Data.Either'
  , Either (..)
  , Result (..)
    -- | Reexport from 'Data.Ord'
  , Ordering (..)
    -- | Reexport from 'Text.Show'
  , ShowS
    -- | Reexport from 'Text.Read'
  , ReadS
    -- | Reexport from 'System.IO'
  , IO
    -- | Reexport from 'System.IO'
  , FilePath
    -- | Reexport from 'System.IO.Error'
  , IOError
    -- | Reexport from 'Data.Void'
  , Void
    -- * Classes
    -- ** Numeric Classes
    -- | Reexport from 'Prelude'
  , Num ((+), (-), (*))
    -- | Reexport from 'Prelude'
  , Real
    -- | Reexport from 'Prelude'
  , Integral
    -- | Reexport from 'Prelude'
  , Fractional ((/))
    -- | Reexport from 'Prelude'
  , Floating ((**))
    -- | Reexport from 'Prelude'
  , RealFrac
    -- | Reexport from 'Prelude'
  , RealFloat
    -- ** The "Theorum-Based" Classes
    -- | Reexport from 'Data.Semigroup'
  , Semigroup ((<>))
    -- | Reexport from 'Data.Monoid'
  , Monoid
    -- | Reexport from 'Control.Monad'
  , Functor (..)
    -- | Reexport from 'Control.Applicative'
  , Alternative (empty, (<|>))
  , Applicative (..)
    -- | Reexport from 'Control.Monad'
  , Monad (..)
    -- | Reexport from 'Control.Monad.IO.Class'
  , MonadIO (..)
    -- | Reexport from 'Control.Monad'
  , MonadPlus
    -- | Reexport from 'Control.Monad.Fail'
  , MonadFail
    -- ** The Rest of the Classes
    -- | Reexport from 'Data.Eq'
  , Eq (..)
    -- | Reexport from 'Data.Ord'
  , Ord ((<), (>), (<=), (>=))
    -- | Reexport from 'Prelude'
  , Enum
    -- | Reexport from 'Prelude'
  , Bounded
    -- | Reexport from 'Data.Foldable'
  , Foldable
    -- | Reexport from 'Data.Traversable'
  , Traversable
    -- | Reexport from 'Text.Show'
  , Show (show, showList)
    -- | Reexport from 'Text.Read'
  , Read
  ) where

import safe           Control.Applicative    ( Alternative (..) )
import safe           Control.Monad          ( MonadPlus (..) )
import safe           Control.Monad.IO.Class ( MonadIO (..) )

import safe           Data.Array             ( Array )
import safe qualified Data.ByteString        as BS ( ByteString )
import safe qualified Data.ByteString.Lazy   as BL ( ByteString )
import safe           Data.List.NonEmpty     ( NonEmpty (..) )
import safe qualified Data.Map               as MapL ( Map )
import safe qualified Data.Map.Strict        as MapS ( Map )
import safe           Data.Sequence          ( Seq (..) )
import safe           Data.Set               ( Set )
import safe qualified Data.Text              as TS ( Text )
import safe qualified Data.Text.Lazy         as TL ( Text )
import safe           Data.Void              ( Void )

import safe           Prelude
  ( Applicative (..)
  , Bool (..)
  , Bounded (..)
  , Char
  , Double
  , Either (..)
  , Enum (..)
  , Eq (..)
  , FilePath
  , Float
  , Floating (..)
  , Foldable (..)
  , Fractional (..)
  , Functor (..)
  , IO
  , IOError
  , Int
  , Integer
  , Integral (..)
  , Maybe (..)
  , Monad (..)
  , MonadFail (..)
  , Monoid (..)
  , Num (..)
  , Ord (..)
  , Ordering (..)
  , Rational
  , Read (..)
  , ReadS
  , Real (..)
  , RealFloat (..)
  , RealFrac (..)
  , Semigroup (..)
  , Show (..)
  , ShowS
  , String
  , Traversable (..)
  , Word
  )


-- | Explicit naming of the 'List' brackets.
type List a = [a]


-- | A two-element Tuple
type Pair a b = (a, b)


-- | A three-element Tuple
type Trio a b c = (a, b, c)


-- | Aliased reexport from 'Data.Text' of the "text" package
type Text = TS.Text


-- | Aliased reexport from 'Data.ByteString' of the "bytestring" package
type ByteString = BS.ByteString


-- | Aliased reexport from 'Data.Text.Lazy' of the "text" package
type TextLazy = TL.Text


-- | Aliased reexport from 'Data.ByteString.Lazy' of the "bytestring" package
type ByteStringLazy = BL.ByteString


-- | Aliased reexport from 'Data.Map.Strict' of the "containers" package
type Map key val = MapS.Map key val


-- | Aliased reexport from 'Data.Map.Lazy' of the "containers" package
type MapLazy key val = MapL.Map key val


{- |
   The 'Result err ok' type, with variants `Err err` and 'Ok ok'.
   Similar to the 'Either' type, but with better naming, and disambiguates the purposes.
-}
data Result err ok
  = Err err
  | Ok ok
  deriving (Eq, Ord, Read, Show)


instance Functor (Result err) where
  fmap :: (okA -> okB) -> Result err okA -> Result err okB
  fmap _ (Err err) = Err err
  fmap fn (Ok ok)  = Ok (fn ok)


instance Applicative (Result err) where
  pure :: ok -> Result err ok
  pure = Ok


  (<*>) :: Result err (okA -> okB) -> Result err okA -> Result err okB
  Err err <*> _  = Err err
  Ok okFn <*> ok = fmap okFn ok


instance Monad (Result err) where
  (>>=) :: Result err okA -> (okA -> Result err okB) -> Result err okB
  Err err >>= _ = Err err
  Ok ok >>= fn  = fn ok