Skip to content

Commit

Permalink
update resolver to lts-22.19.
Browse files Browse the repository at this point in the history
allows use of ghc-9.4.8
  • Loading branch information
esapulkkinen committed May 2, 2024
1 parent 9d8c0b2 commit 0438739
Show file tree
Hide file tree
Showing 81 changed files with 2,245 additions and 1,300 deletions.
11 changes: 11 additions & 0 deletions Math/Graph/Action.lhs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
>{-# OPTIONS_HADDOCK prune #-}
>{-# LANGUAGE Safe,FlexibleInstances, MultiParamTypeClasses, TypeOperators #-}
>{-# LANGUAGE FunctionalDependencies #-}
>-- | Module: Math.Graph.Action
>-- Copyright: Esa Pulkkinen, 2018
>-- License: LGPL
Expand All @@ -22,6 +23,16 @@
>-- | See Lawvere,Rosebrugh: Sets for mathematics
>newtype x :<-: a = Action { runAction :: a -> x }

>class (Contravariant f, Contravariant g) => ContraAdjunction f g | f -> g, g -> f where
> contraLeftAdjunct :: (f a :<-: b) -> a :<-: g b
> contraRightAdjunct :: (a :<-: g b) -> f a :<-: b
> contraUnit :: a :<-: g (f a)
> contraCounit :: f (g b) :<-: b
> contraUnit = contraLeftAdjunct (Action id)
> contraCounit = contraRightAdjunct (Action id)

>infixr 8 =*=

>(=*=) :: x :<-: b -> (a -> b) -> x :<-: a
>(Action e) =*= m = Action $ e . m
Expand Down
69 changes: 69 additions & 0 deletions Math/Graph/Category.lhs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
>{-# LANGUAGE GADTs, DataKinds, KindSignatures, PolyKinds, TypeOperators #-}
>{-# LANGUAGE StandaloneDeriving, RankNTypes #-}
>{-# LANGUAGE TypeFamilies, MultiParamTypeClasses #-}
>{-# LANGUAGE FunctionalDependencies, FlexibleContexts #-}
>module Math.Graph.Category where
>import Data.Set
>import Math.Tools.NaturalTransformation
>import Math.Tools.FixedPoint
>import qualified Control.Category as Cat
>import Prelude hiding ((.), id, Monad(..))
>import qualified Prelude (Monad(..),id,(.))

>class (Cat.Category arr, Cat.Category arr') => Adjunction2 arr arr' f g
> | f -> g, g -> f, arr -> arr', arr' -> arr where
> lad :: arr (f a) b -> arr' a (g b)
> rad :: arr' a (g b) -> arr (f a) b
> unit :: arr' a (g (f a))
> counit :: arr (f (g b)) b

>class Category3 arr where
> point3 :: arr a a a
> line3 :: arr a a b
> rotate3 :: arr a b c -> arr b c a

compose3 :: arr a b c -> arr b d c -> arr d e c -> arr e f c -> arr f g c
-> arr (

A-----G AC
/\ / \ | \
/ \ / \ | \
B----C-----F ==> | FC
\ / \ / | /
\/ \ / | /
D----E DC

>class (Category3 arr, Category3 arr', Category3 arr'')
> => Adjunction3 arr arr' arr'' f g h
> | f -> g, g -> h, h -> f, arr -> arr', arr' -> arr'', arr'' -> arr where
> lad3 :: arr (f a) b c -> arr' a (g b) c
> mad3 :: arr' a (g b) c -> arr'' a b (h c)
> rad3 :: arr'' a b (h c) -> arr (f a) b c
> unit3 :: arr' a (g (f a)) (f a)
> munit3 :: arr'' (g b) b (h (g b))
> counit3 :: arr (f (h c)) (h c) c

>data Iso (arr :: k -> k -> *) (a :: k) (b :: k) where
> (:<->:) :: arr a b -> arr b a -> Iso arr a b

>data NatT f g = NatT { unNatT :: forall a. f a -> g a }
>data NatIso f g = NatIso { unNatIso :: forall a. Iso (->) (f a) (g a) }

>data KleisliA a b = KleisliA { unKleisliA :: a -> IO b }

>instance Cat.Category NatT where
> id = NatT Cat.id
> (NatT f) . (NatT g) = NatT (f Cat.. g)

>instance Cat.Category KleisliA where
> id = KleisliA Prelude.return
> (KleisliA f) . (KleisliA g) = KleisliA $ \a -> g a Prelude.>>= f

>instance (Cat.Category arr) => Cat.Category (Iso arr) where
> id = Cat.id :<->: Cat.id
> (f :<->: g) . (f' :<->: g') = (f Cat.. f') :<->: (g' Cat.. g)

>type family Hom (a :: k) (b :: k) :: *
>type instance Hom a b = NatT a b
>type instance Hom a b = KleisliA a b

7 changes: 5 additions & 2 deletions Math/Graph/GraphMonad.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
> ~(GraphM f) <*> ~(GraphM x) = GraphM $ f <*> x

>instance (Monoid g) => Monad (GraphM g) where
> return x = GraphM (mempty,x)
> return = pure
> ~(GraphM ~(a,x)) >>= g = let
> ~(GraphM ~(b,y)) = g x
> in GraphM (mappend a b,y)

>instance (Monoid g) => MonadFail (GraphM g) where
> fail msg = GraphM (mempty,error msg)

>-- <https://downloads.haskell.org/ghc/latest/docs/libraries/mtl-2.2.2/Control-Monad-Writer-Lazy.html#t:MonadWriter>
Expand All @@ -49,8 +51,9 @@
> ~(GraphMT f) <*> ~(GraphMT x) = GraphMT $ \act -> f act <*> x act

>instance (Monoid g, Monad m) => Monad (GraphMT m g) where
> return x = GraphMT $ \act -> act x mempty
> ~(GraphMT f) >>= g = GraphMT $ \act -> f act >>= \a -> runGraphMT (g a) act

>instance (Monoid g, MonadFail m) => MonadFail (GraphMT m g) where
> fail msg = GraphMT $ \_ -> fail msg

>actMT :: (Monad m) => g -> GraphMT m g a -> GraphMT m g a
Expand Down
27 changes: 18 additions & 9 deletions Math/Graph/GraphMonoid.lhs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
>{-# LANGUAGE Safe,FlexibleInstances, MultiParamTypeClasses, TypeOperators, DeriveGeneric, DeriveDataTypeable, LambdaCase #-}
>{-# LANGUAGE OverloadedStrings, StandaloneDeriving, GADTs #-}
>{-# LANGUAGE UndecidableInstances, KindSignatures, ConstraintKinds #-}
>{-# LANGUAGE Arrows, FlexibleContexts #-}
>{-# LANGUAGE Arrows, FlexibleContexts, PolyKinds #-}
>module Math.Graph.GraphMonoid where
>import Control.Arrow
>import qualified Control.Category as Cat
Expand Down Expand Up @@ -32,6 +32,12 @@
>data GraphElem v e = Vertex v | Edge e
> deriving (Eq, Ord, Show, Read)

>data ReversibleGraphProp v e = VertexProp v
> | EdgeProp e
> | LoopProp e
> | OneLaneLoopProp e
> | BandProp e

>deriving instance (Typeable v, Typeable e) => Typeable (GraphElem v e)
>deriving instance (Data v, Data e) => Data (GraphElem v e)

Expand All @@ -50,7 +56,8 @@
instance (Universe v, Universe e) => Universe (GraphElem v e) where
all_elements = (map Vertex all_elements) ++ (map Edge all_elements)

>class (Eq (arr a a), Monoid.Monoid (arr a a)) => GraphMonoid arr a where
>class (Cat.Category arr, Eq (arr a a), Monoid.Monoid (arr a a))
> => GraphMonoid arr a where
> gdom :: arr a a
> gcod :: arr a a

Expand Down Expand Up @@ -97,7 +104,10 @@ data Three = TId | TDom | TCod deriving (Eq,Show,Ord, Typeable, Data, Generic)

>-- | intent is that g =~= F Bool, where F : 2^{op} -> Set. But opposite categories are difficult to represent.
>three_action_arr :: (ArrowChoice arr) => arr g g -> arr g g -> arr g g -> Three Bool Bool -> arr g g
>three_action_arr a b c f = proc i -> case f of { TId -> a -< i ; TDom -> b -< i ; TCod -> c -< i }
>three_action_arr a b c TId = proc i -> a -< i
>three_action_arr a b c TDom = proc i -> b -< i
>three_action_arr a b c TCod = proc i -> c -< i


>instance (Arrow arr) => MonoidArrow arr (Three Bool Bool) Bool where
> monoidA TId = arr id
Expand Down Expand Up @@ -152,11 +162,10 @@ data Three = TId | TDom | TCod deriving (Eq,Show,Ord, Typeable, Data, Generic)
>-- | intent is that g =~= F2, where F : 2^{op} -> Set. But opposite categories are difficult to represent.
>four_action_arr :: (ArrowChoice arr)
> => arr g g -> arr g g -> arr g g -> arr g g -> Four Bool Bool -> arr g g
>four_action_arr aid adom acod anot f = proc v -> case f of
> FId -> aid -< v
> FDom -> adom -< v
> FCod -> acod -< v
> FNot -> anot -< v
>four_action_arr aid adom acod anot FId = proc v -> aid -< v
>four_action_arr aid adom acod anot FDom = proc v -> adom -< v
>four_action_arr aid adom acod anot FCod = proc v -> acod -< v
>four_action_arr aid adom acod anot FNot = proc v -> anot -< v

>-- | intent is that g =~= F2, where F : 2^{op} -> Set. But opposite categories are difficult to represent.
>four_action :: (g -> g) -> (g -> g) -> (g -> g) -> (g -> g) -> Four Bool Bool -> Endo g
Expand Down Expand Up @@ -347,5 +356,5 @@ data Three = TId | TDom | TCod deriving (Eq,Show,Ord, Typeable, Data, Generic)
>mapEndo f = (\ (Endo g) -> Endo (runIso f . g . runIsoInverse f))
> <-> (\ (Endo h) -> Endo (runIsoInverse f . h . runIso f))
>instance FunctorArrow Endo (:==:) where
>instance FunctorArrow Endo (:==:) (:==:) where
> amap = mapEndo
6 changes: 5 additions & 1 deletion Math/Graph/InGraphMonad.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
>isTargetVertexM element = targetM element >>= \s -> return (s == element)
>isVertexM :: (GraphMonoid mon Bool, Monad m, Eq e) => e -> InGraphM mon e m Bool
>isVertexM e = liftM2 (&&) (isSourceVertexM e) (isTargetVertexM e)
>isVertexM e = liftA2 (&&) (isSourceVertexM e) (isTargetVertexM e)
>isEdgeM :: (GraphMonoid mon Bool, Monad m, Eq e) => e -> InGraphM mon e m Bool
>isEdgeM element = isVertexM element >>= (return . not)
Expand All @@ -219,6 +219,10 @@
> => e -> InGraphM mon e m Bool
>isOneLaneLoopM edge = inverseM edge >>= \ie -> return (ie == edge)
>isBandM :: (Eq e, Monad m, ReversibleGraphMonoid mon Bool)
> => e -> InGraphM mon e m Bool
>isBandM edge = inverseM edge >>= \ie -> return (ie /= edge)
>instance (Ord a, GraphMonoid m Bool) => Visitor (Graph m a) where
> data Fold (Graph m a) b = GraphFold {
> graphfold_initial :: b,
Expand Down
3 changes: 3 additions & 0 deletions Math/Graph/Interface.lhs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
>{-# LANGUAGE Safe, MultiParamTypeClasses, FunctionalDependencies #-}
>{-# LANGUAGE DefaultSignatures #-}
>module Math.Graph.Interface where
>import Prelude hiding (id, (.))
>import Control.Arrow
>import qualified Data.Set as Set
>import Data.Set (Set)
>import qualified Data.Map as Map
>import Data.Map (Map)
>import Math.Tools.Set
>import Control.Category
>
>class DigraphFactory g v e | g -> v, g -> e, v e -> g where
> vertexGraph :: v -> g
Expand Down Expand Up @@ -109,3 +111,4 @@
> e' <- ginverse e
> yx <- gisEdgeBetween e' x y
> return (xy || yx)

5 changes: 5 additions & 0 deletions Math/Graph/InternalCategory.lhs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
>{-# LANGUAGE Safe, KindSignatures, PolyKinds #-}
>module Math.Graph.InternalCategory where
>import Data.Kind
>import safe Control.Arrow

3 changes: 1 addition & 2 deletions Math/Graph/Labeled.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
>data LGraph lbl mon a = LGraph { lgraph_basegraph :: Graph mon a,
> lgraph_labels :: a :==: lbl }
>
>labelsFromMaps :: (Ord a, Ord lbl, Monad m) => Map lbl a -> Map a lbl
>labelsFromMaps :: (Ord a, Ord lbl, MonadFail m) => Map lbl a -> Map a lbl
> -> Graph mon a -> m (LGraph lbl mon a)
>labelsFromMaps m n g = orderedMapIso n m >>= (return . LGraph g)

Expand Down Expand Up @@ -72,7 +72,6 @@
> (InLGraphM f) <*> (InLGraphM x) = InLGraphM (f <*> x)

>instance (Monad m) => Monad (InLGraphM mon lbl e m) where
> return = InLGraphM . return
> (InLGraphM f) >>= g = InLGraphM (f >>= (runInLGraphM . g))

>instance MonadTrans (InLGraphM mon lbl e) where
Expand Down
22 changes: 11 additions & 11 deletions Math/Graph/RDF.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
> triple lnk sourcePropURI v1',
> triple lnk targetPropURI v2',
> triple lnk inversePropURI lnk ]
> where lnk = bnode n
> where lnk = bnodeUnsafe n
> v1' = unode v1
> v2' = unode v2
>rdfReversibleLink n m v1 v2 =[
Expand All @@ -54,19 +54,19 @@
> triple lnk2 sourcePropURI v2',
> triple lnk2 targetPropURI v1',
> triple lnk2 inversePropURI lnk]
> where lnk = bnode n
> lnk2 = bnode m
> where lnk = bnodeUnsafe n
> lnk2 = bnodeUnsafe m
> v1' = unode v1
> v2' = unode v2

>rdfLink :: Text -> Object -> Object -> Triples
>rdfLink n v1 v2 = [triple lnk linkNameURI (lnode $ plainL n),
> triple lnk sourcePropURI v1,
> triple lnk targetPropURI v2]
> where lnk = bnode n
> where lnk = bnodeUnsafe n
>
>rdfVertex :: Text -> Triples
>rdfVertex v = [triple (bnode v) vertexNameURI (lnode $ plainL v)]
>rdfVertex v = [triple (bnodeUnsafe v) vertexNameURI (lnode $ plainL v)]


>graphsToRDF :: (Monad m, ReversibleGraphMonoid mon Bool)
Expand All @@ -80,7 +80,7 @@
>namedGraphToTriples :: (Monad m, ReversibleGraphMonoid mon Bool)
> => Text -> InGraphM mon Text m Triples
>namedGraphToTriples graphname = do
> let gnode = bnode graphname
> let gnode = bnodeUnsafe graphname
> triples <- graphToTriples
> vert <- gvertices
> let vertTriples = Set.map (\v -> triple gnode verticesURI (unode v)) vert
Expand All @@ -106,7 +106,7 @@
> (PrefixMappings $ Map.singleton "graph" baseURL)
> return $ rdf

>rdfToGraph :: (Monad m) => RDF TList -> Node -> m (Graph Four Node)
>rdfToGraph :: (MonadFail m) => RDF TList -> Node -> m (Graph Four Node)
>rdfToGraph rdf graph = do
> let vertices = query rdf (Just graph) (Just vertexURI) Nothing
> let links = query rdf (Just graph) (Just linkURI) Nothing
Expand All @@ -117,7 +117,7 @@

>type Graphs = Map Node (Graph Four Node)

>rdfToGraphs :: (Monad m) => RDF TList -> m Graphs
>rdfToGraphs :: (MonadFail m) => RDF TList -> m Graphs
>rdfToGraphs rdf = do
> let graphs = query rdf Nothing (Just graphNameURI) Nothing
> graphlist <- mapM handleTriple graphs
Expand All @@ -134,11 +134,11 @@
> Right rdf -> rdfToGraphs rdf


>convertVertex :: (Monad m) => RDF TList -> Triple -> m Node
>convertVertex :: (MonadFail m) => RDF TList -> Triple -> m Node
>convertVertex rdf (Triple subj pred obj)
> = getUniqueObject (query rdf (Just obj) (Just vertexNameURI) Nothing)

>convertLink :: (Monad m) => RDF TList -> Triple -> m ((Node,Node),(Node,Node))
>convertLink :: (MonadFail m) => RDF TList -> Triple -> m ((Node,Node),(Node,Node))
>convertLink rdf (Triple subj pred obj) = do
> linkname <- getUniqueObject $
> query rdf (Just obj) (Just linkNameURI) Nothing
Expand All @@ -152,7 +152,7 @@
> query rdf (Just inverse) (Just linkNameURI) Nothing
> return $ ((linkname,inversename),(source,target))

>getUniqueObject :: (Monad m) => [Triple] -> m Node
>getUniqueObject :: (MonadFail m) => [Triple] -> m Node
>getUniqueObject [t] = return $ objectOf t
>getUniqueObject _ = fail "uniqueness constraint violated"
51 changes: 51 additions & 0 deletions Math/Graph/Tex.lhs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
>{-# LANGUAGE Safe #-}
>module Math.Graph.Tex where
>import Math.Graph.Reversible
>import Math.Graph.InGraphMonad
>import Data.Set

>packageImports = "\\usepackage{tikz}"

>data TexToken = EnvToken { envName :: String,
> envOpts :: [String],
> contents :: [TexToken] }
> | NodesToken { nodesList :: [TikzNode] }
> | EdgesToken { edgesList :: [TikzEdge] }

>data NodeType = NodeType {
> style_name :: String,
> style_def :: String
> }

>data TikzNode = TikzNode {
> node_type :: NodeType,
> node_name :: String
> }
>data TikzEdge = TikzEdge {
> edge_name :: String,
> start_node_name :: String,
> end_node_name :: String,
> start_node_direction :: NodeDirection,
> end_node_direction :: NodeDirection
> }
>


>instance Show TexToken where
> show (EnvToken e o c) =
> "\\begin{" ++ e ++ "}[" ++ concatMap (++ ',') o ++ "]\n"
> ++ concatMap (\x -> show x ++ "\n") c
> ++ "\\end{" ++ e ++ "}\n"

>tikzEnv :: [String] -> TexToken -> TexToken
>tikzEnv opts cont = EnvToken "tikzpicture" opts cont

>graphToTex :: (Monad m) => InGraphM mon e m TexToken
>graphToTex = do
> v <- gvertices
> e <- glinks
> let links = Set.map linkToTex e
> vertices = Set.map vertexToTex e
> return $ tikzEnv [] $ NodesToken $ [

>linkToTex ::
4 changes: 2 additions & 2 deletions Math/Matrix/Bitmap.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
> bitmapString = [color (bm ! i ! j)
> | i <- range bmbound,
> j <- range (bounds (bm ! i))]
> header lst = "P6 " ++ show (snd $ bounds (bm ! fst bmbound))
> ++ " " ++ show (snd bmbound) ++ " 255\n"
> header lst = "P6 " ++ show (A.rangeSize $ bounds (bm ! fst bmbound))
> ++ " " ++ show (A.rangeSize bmbound) ++ " 255\n"
> packedHeader = ByteString.pack $!
> map (toEnum . fromEnum) (header bitmapString)
> color i = colortable ! i
Expand Down
Loading

0 comments on commit 0438739

Please sign in to comment.