{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE StandaloneDeriving #-}
module OAlg.Structure.Fibred.Definition
(
Fibred(..), Fbr, ForgetfulFbr
, FibredOriented, FbrOrt, ForgetfulFbrOrt
, OrdRoot, TotalRoot
, Sheaf(..)
)
where
import Control.Exception
import Data.List((++),map)
import Data.Foldable
import OAlg.Prelude
import OAlg.Data.Canonical
import OAlg.Data.Singleton
import OAlg.Structure.Exception
import OAlg.Structure.Oriented.Definition
import OAlg.Structure.Multiplicative.Definition
class (Entity f, Entity (Root f)) => Fibred f where
type Root f
root :: f -> Root f
default root :: (Root f ~ Orientation (Point f), Oriented f) => f -> Root f
root = forall q. Oriented q => q -> Orientation (Point q)
orientation
class (Fibred d, Oriented d, Root d ~ Orientation (Point d)) => FibredOriented d
data FOr
type instance Structure FOr x = FibredOriented x
instance Fibred () where
type Root () = Orientation ()
instance FibredOriented ()
instance Fibred Int where
type Root Int = Orientation ()
instance FibredOriented Int
instance Fibred Integer where
type Root Integer = Orientation ()
instance FibredOriented Integer
instance Fibred N where
type Root N = Orientation ()
instance FibredOriented N
instance Fibred Z where
type Root Z = Orientation ()
instance FibredOriented Z
instance Fibred Q where
type Root Q = Orientation ()
instance FibredOriented Q
instance Entity p => Fibred (Orientation p) where
type Root (Orientation p) = Orientation p
instance Entity p => FibredOriented (Orientation p)
instance FibredOriented f => Fibred (Op f) where
type Root (Op f) = Orientation (Point f)
instance FibredOriented f => FibredOriented (Op f)
class Ord (Root f) => OrdRoot f
class Singleton (Root f) => TotalRoot f
data Sheaf f = Sheaf (Root f) [f]
deriving instance Fibred f => Show (Sheaf f)
deriving instance Fibred f => Eq (Sheaf f)
instance Foldable Sheaf where
foldr :: forall a b. (a -> b -> b) -> b -> Sheaf a -> b
foldr a -> b -> b
op b
b (Sheaf Root a
_ [a]
fs) = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr a -> b -> b
op b
b [a]
fs
instance Fibred f => Validable (Sheaf f) where
valid :: Sheaf f -> Statement
valid (Sheaf Root f
r [f]
fs) = forall a. Validable a => a -> Statement
valid Root f
r forall b. Boolean b => b -> b -> b
&& forall {f}. Fibred f => Root f -> [f] -> Statement
vld Root f
r [f]
fs where
vld :: Root f -> [f] -> Statement
vld Root f
_ [] = Statement
SValid
vld Root f
r (f
f:[f]
fs) = forall a. Validable a => a -> Statement
valid f
f forall b. Boolean b => b -> b -> b
&& (forall f. Fibred f => f -> Root f
root f
f forall a. Eq a => a -> a -> Statement
.==. Root f
r) forall b. Boolean b => b -> b -> b
&& Root f -> [f] -> Statement
vld Root f
r [f]
fs
instance Fibred f => Entity (Sheaf f)
instance Fibred f => Fibred (Sheaf f) where
type Root (Sheaf f) = Root f
root :: Sheaf f -> Root (Sheaf f)
root (Sheaf Root f
r [f]
_) = Root f
r
instance Fibred f => Oriented (Sheaf f) where
type Point (Sheaf f) = Root f
orientation :: Sheaf f -> Orientation (Point (Sheaf f))
orientation Sheaf f
s = forall f. Fibred f => f -> Root f
root Sheaf f
s forall p. p -> p -> Orientation p
:> forall f. Fibred f => f -> Root f
root Sheaf f
s
instance Fibred f => Multiplicative (Sheaf f) where
one :: Point (Sheaf f) -> Sheaf f
one Point (Sheaf f)
r = forall f. Root f -> [f] -> Sheaf f
Sheaf Point (Sheaf f)
r []
Sheaf Root f
r [f]
fs * :: Sheaf f -> Sheaf f -> Sheaf f
* Sheaf Root f
s [f]
gs | Root f
r forall a. Eq a => a -> a -> Bool
== Root f
s = forall f. Root f -> [f] -> Sheaf f
Sheaf Root f
r ([f]
fsforall a. [a] -> [a] -> [a]
++[f]
gs)
| Bool
otherwise = forall a e. Exception e => e -> a
throw ArithmeticException
NotMultiplicable
type instance Dual (Sheaf f) = Sheaf (Op f)
instance FibredOriented f => Dualisable (Sheaf f) where
toDual :: Sheaf f -> Dual (Sheaf f)
toDual (Sheaf Root f
r [f]
fs) = forall f. Root f -> [f] -> Sheaf f
Sheaf (forall x. Transposable x => x -> x
transpose Root f
r) (forall a b. (a -> b) -> [a] -> [b]
map forall x. x -> Op x
Op [f]
fs)
fromDual :: Dual (Sheaf f) -> Sheaf f
fromDual (Sheaf Root (Op f)
r' [Op f]
fs') = forall f. Root f -> [f] -> Sheaf f
Sheaf (forall x. Transposable x => x -> x
transpose Root (Op f)
r') (forall a b. (a -> b) -> [a] -> [b]
map forall x. Op x -> x
fromOp [Op f]
fs')
instance Fibred f => Embeddable f (Sheaf f) where
inj :: f -> Sheaf f
inj f
a = forall f. Root f -> [f] -> Sheaf f
Sheaf (forall f. Fibred f => f -> Root f
root f
a) [f
a]
data Fbr
type instance Structure Fbr x = Fibred x
instance Transformable Fbr Typ where tau :: forall x. Struct Fbr x -> Struct Typ x
tau Struct Fbr x
Struct = forall s x. Structure s x => Struct s x
Struct
instance Transformable Fbr Ent where tau :: forall x. Struct Fbr x -> Struct Ent x
tau Struct Fbr x
Struct = forall s x. Structure s x => Struct s x
Struct
class Transformable s Fbr => ForgetfulFbr s
instance ForgetfulTyp Fbr
instance ForgetfulFbr Fbr
data FbrOrt
type instance Structure FbrOrt x = FibredOriented x
instance Transformable FbrOrt Typ where tau :: forall x. Struct FbrOrt x -> Struct Typ x
tau Struct FbrOrt x
Struct = forall s x. Structure s x => Struct s x
Struct
instance Transformable FbrOrt Ent where tau :: forall x. Struct FbrOrt x -> Struct Ent x
tau Struct FbrOrt x
Struct = forall s x. Structure s x => Struct s x
Struct
instance Transformable FbrOrt Fbr where tau :: forall x. Struct FbrOrt x -> Struct Fbr x
tau Struct FbrOrt x
Struct = forall s x. Structure s x => Struct s x
Struct
instance Transformable FbrOrt Ort where tau :: forall x. Struct FbrOrt x -> Struct Ort x
tau Struct FbrOrt x
Struct = forall s x. Structure s x => Struct s x
Struct
class ( ForgetfulFbr s, ForgetfulOrt s
, Transformable s FbrOrt
) => ForgetfulFbrOrt s
instance ForgetfulTyp FbrOrt
instance ForgetfulOrt FbrOrt
instance ForgetfulFbr FbrOrt
instance ForgetfulFbrOrt FbrOrt