{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}

-- |
-- Module      : OAlg.Data.Identity
-- Description : identical predicate
-- Copyright   : (c) Erich Gut
-- License     : BSD3
-- Maintainer  : zerich.gut@gmail.com
-- 
-- identical predicate.
module OAlg.Data.Identity
  ( Id(..)
  , fromId
  , trafoFromId
  , trafoToId
  )
  where

--------------------------------------------------------------------------------
-- Id -

-- | identical predicate.
newtype Id x = Id x
  deriving ( Int -> Id x -> ShowS
forall x. Show x => Int -> Id x -> ShowS
forall x. Show x => [Id x] -> ShowS
forall x. Show x => Id x -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Id x] -> ShowS
$cshowList :: forall x. Show x => [Id x] -> ShowS
show :: Id x -> String
$cshow :: forall x. Show x => Id x -> String
showsPrec :: Int -> Id x -> ShowS
$cshowsPrec :: forall x. Show x => Int -> Id x -> ShowS
Show,ReadPrec [Id x]
ReadPrec (Id x)
ReadS [Id x]
forall x. Read x => ReadPrec [Id x]
forall x. Read x => ReadPrec (Id x)
forall x. Read x => Int -> ReadS (Id x)
forall x. Read x => ReadS [Id x]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Id x]
$creadListPrec :: forall x. Read x => ReadPrec [Id x]
readPrec :: ReadPrec (Id x)
$creadPrec :: forall x. Read x => ReadPrec (Id x)
readList :: ReadS [Id x]
$creadList :: forall x. Read x => ReadS [Id x]
readsPrec :: Int -> ReadS (Id x)
$creadsPrec :: forall x. Read x => Int -> ReadS (Id x)
Read,Id x -> Id x -> Bool
forall x. Eq x => Id x -> Id x -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Id x -> Id x -> Bool
$c/= :: forall x. Eq x => Id x -> Id x -> Bool
== :: Id x -> Id x -> Bool
$c== :: forall x. Eq x => Id x -> Id x -> Bool
Eq,Id x -> Id x -> Bool
Id x -> Id x -> Ordering
Id x -> Id x -> Id x
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {x}. Ord x => Eq (Id x)
forall x. Ord x => Id x -> Id x -> Bool
forall x. Ord x => Id x -> Id x -> Ordering
forall x. Ord x => Id x -> Id x -> Id x
min :: Id x -> Id x -> Id x
$cmin :: forall x. Ord x => Id x -> Id x -> Id x
max :: Id x -> Id x -> Id x
$cmax :: forall x. Ord x => Id x -> Id x -> Id x
>= :: Id x -> Id x -> Bool
$c>= :: forall x. Ord x => Id x -> Id x -> Bool
> :: Id x -> Id x -> Bool
$c> :: forall x. Ord x => Id x -> Id x -> Bool
<= :: Id x -> Id x -> Bool
$c<= :: forall x. Ord x => Id x -> Id x -> Bool
< :: Id x -> Id x -> Bool
$c< :: forall x. Ord x => Id x -> Id x -> Bool
compare :: Id x -> Id x -> Ordering
$ccompare :: forall x. Ord x => Id x -> Id x -> Ordering
Ord,Int -> Id x
Id x -> Int
Id x -> [Id x]
Id x -> Id x
Id x -> Id x -> [Id x]
Id x -> Id x -> Id x -> [Id x]
forall x. Enum x => Int -> Id x
forall x. Enum x => Id x -> Int
forall x. Enum x => Id x -> [Id x]
forall x. Enum x => Id x -> Id x
forall x. Enum x => Id x -> Id x -> [Id x]
forall x. Enum x => Id x -> Id x -> Id x -> [Id x]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Id x -> Id x -> Id x -> [Id x]
$cenumFromThenTo :: forall x. Enum x => Id x -> Id x -> Id x -> [Id x]
enumFromTo :: Id x -> Id x -> [Id x]
$cenumFromTo :: forall x. Enum x => Id x -> Id x -> [Id x]
enumFromThen :: Id x -> Id x -> [Id x]
$cenumFromThen :: forall x. Enum x => Id x -> Id x -> [Id x]
enumFrom :: Id x -> [Id x]
$cenumFrom :: forall x. Enum x => Id x -> [Id x]
fromEnum :: Id x -> Int
$cfromEnum :: forall x. Enum x => Id x -> Int
toEnum :: Int -> Id x
$ctoEnum :: forall x. Enum x => Int -> Id x
pred :: Id x -> Id x
$cpred :: forall x. Enum x => Id x -> Id x
succ :: Id x -> Id x
$csucc :: forall x. Enum x => Id x -> Id x
Enum,Id x
forall a. a -> a -> Bounded a
forall x. Bounded x => Id x
maxBound :: Id x
$cmaxBound :: forall x. Bounded x => Id x
minBound :: Id x
$cminBound :: forall x. Bounded x => Id x
Bounded
           , forall a b. a -> Id b -> Id a
forall a b. (a -> b) -> Id a -> Id b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Id b -> Id a
$c<$ :: forall a b. a -> Id b -> Id a
fmap :: forall a b. (a -> b) -> Id a -> Id b
$cfmap :: forall a b. (a -> b) -> Id a -> Id b
Functor
           , forall a. Eq a => a -> Id a -> Bool
forall a. Num a => Id a -> a
forall a. Ord a => Id a -> a
forall m. Monoid m => Id m -> m
forall a. Id a -> Bool
forall a. Id a -> Int
forall a. Id a -> [a]
forall a. (a -> a -> a) -> Id a -> a
forall m a. Monoid m => (a -> m) -> Id a -> m
forall b a. (b -> a -> b) -> b -> Id a -> b
forall a b. (a -> b -> b) -> b -> Id a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Id a -> a
$cproduct :: forall a. Num a => Id a -> a
sum :: forall a. Num a => Id a -> a
$csum :: forall a. Num a => Id a -> a
minimum :: forall a. Ord a => Id a -> a
$cminimum :: forall a. Ord a => Id a -> a
maximum :: forall a. Ord a => Id a -> a
$cmaximum :: forall a. Ord a => Id a -> a
elem :: forall a. Eq a => a -> Id a -> Bool
$celem :: forall a. Eq a => a -> Id a -> Bool
length :: forall a. Id a -> Int
$clength :: forall a. Id a -> Int
null :: forall a. Id a -> Bool
$cnull :: forall a. Id a -> Bool
toList :: forall a. Id a -> [a]
$ctoList :: forall a. Id a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Id a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Id a -> a
foldr1 :: forall a. (a -> a -> a) -> Id a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Id a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Id a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Id a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Id a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Id a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Id a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Id a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Id a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Id a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Id a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Id a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Id a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Id a -> m
fold :: forall m. Monoid m => Id m -> m
$cfold :: forall m. Monoid m => Id m -> m
Foldable
           )

--------------------------------------------------------------------------------
-- formId -

-- | deconstructs 'Id'.
fromId :: Id x -> x
fromId :: forall x. Id x -> x
fromId (Id x
x) = x
x

--------------------------------------------------------------------------------
-- trafoFromId -

-- | transforming a @f :: x -> 'Id' y@ to a @f' :: x -> i z@.
trafoFromId :: (y -> i z) -> (x -> Id y) -> x -> i z
trafoFromId :: forall y (i :: * -> *) z x. (y -> i z) -> (x -> Id y) -> x -> i z
trafoFromId y -> i z
i x -> Id y
f x
x = y -> i z
i y
y where Id y
y = x -> Id y
f x
x

--------------------------------------------------------------------------------
-- trafoToId -

-- | transforming a @f :: x -> y@ to a @f' :: x -> Id y@.
trafoToId :: (x -> y) -> x -> Id y
trafoToId :: forall x y. (x -> y) -> x -> Id y
trafoToId x -> y
f = forall x. x -> Id x
Id forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> y
f