Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bifunctor instance for labelled graphs
Browse files Browse the repository at this point in the history
Closes: #156
andreabedini committed Jan 22, 2019
1 parent 186ed22 commit 45eded9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Algebra/Graph/Labelled.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE DeriveFunctor, FlexibleInstances #-}
{-# LANGUAGE CPP, DeriveFunctor, FlexibleInstances #-}
-----------------------------------------------------------------------------
-- |
-- Module : Algebra.Graph.Labelled
@@ -46,6 +46,9 @@ module Algebra.Graph.Labelled (
import Prelude ()
import Prelude.Compat

#if MIN_VERSION_base(4,8,0)
import Data.Bifunctor
#endif
import Data.Monoid (Any (..))
import Data.Semigroup ((<>))

@@ -82,6 +85,11 @@ instance (Ord a, Num a, Dioid e) => Num (Graph e a) where
abs = id
negate = id

#if MIN_VERSION_base(4,8,0)
instance Bifunctor Graph where
bimap f g = emap f . fmap g
#endif

-- TODO: This is a very inefficient implementation. Find a way to construct an
-- adjacency map directly, without building intermediate representations for all
-- subgraphs.

0 comments on commit 45eded9

Please sign in to comment.