Skip to content

Commit

Permalink
Add NFData Graph instance (snowleopard#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej authored and snowleopard committed Nov 11, 2017
1 parent c1d0e9a commit 8b9cbd8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dist
dist-*
.ghc.environment.*
cabal-dev
*.o
*.hi
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## next

* add `NFData Graph` instance

## 0.0.5

* Add `dfs`.
Expand Down
3 changes: 2 additions & 1 deletion algebraic-graphs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ library
Algebra.Graph.Relation.Transitive
build-depends: array >= 0.5 && < 0.8,
base >= 4.9 && < 5,
containers >= 0.5 && < 0.8
containers >= 0.5 && < 0.8,
deepseq >= 1.4.2.0 && <1.5
default-language: Haskell2010
default-extensions: FlexibleContexts
GeneralizedNewtypeDeriving
Expand Down
7 changes: 7 additions & 0 deletions src/Algebra/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module Algebra.Graph (
) where

import Control.Applicative (Alternative, (<|>))
import Control.DeepSeq (NFData (..))
import Control.Monad

import qualified Algebra.Graph.AdjacencyMap as AM
Expand Down Expand Up @@ -138,6 +139,12 @@ data Graph a = Empty
| Connect (Graph a) (Graph a)
deriving (Foldable, Functor, Show, Traversable)

instance NFData a => NFData (Graph a) where
rnf Empty = ()
rnf (Vertex a) = rnf a
rnf (Overlay x y) = rnf x `seq` rnf y
rnf (Connect x y) = rnf x `seq` rnf y

instance C.Graph (Graph a) where
type Vertex (Graph a) = a
empty = empty
Expand Down

0 comments on commit 8b9cbd8

Please sign in to comment.