on master help sign in
Binary instance for DirectedGraph
commit99233f830cead0dea265eb5ec708f781295e734e authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSun 20 Mar 2011, 15:14 (16 years ago) parent18d19e0
1 file changed+9−1
src/Hakyll/Core/DirectedGraph/Internal.hs+9−1
src/Hakyll/Core/DirectedGraph/Internal.hs+9−1
@@ -1,18 +1,22 @@
11-- | Internal structure of the DirectedGraph type. Not exported outside of the
22-- library.
33--
4+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
45module Hakyll.Core.DirectedGraph.Internal
56 ( Node (..)
67 , DirectedGraph (..)
78 ) where
89
910import Prelude hiding (reverse, filter)
11+import Control.Applicative ((<$>), (<*>))
1012import Data.Monoid (Monoid, mempty, mappend)
1113import Data.Set (Set)
1214import Data.Map (Map)
1315import qualified Data.Map as M
1416import qualified Data.Set as S
1517
18+import Data.Binary (Binary, put, get)
19+
1620-- | A node in the directed graph
1721--
1822data Node a = Node
@@ -20,6 +24,10 @@ data Node a = Node
2024 , nodeNeighbours :: Set a -- ^ Edges starting at this node
2125 } deriving (Show)
2226
27+instance (Binary a, Ord a) => Binary (Node a) where
28+ put (Node t n) = put t >> put n
29+ get = Node <$> get <*> get
30+
2331-- | Append two nodes. Useful for joining graphs.
2432--
2533appendNodes :: Ord a => Node a -> Node a -> Node a
@@ -33,7 +41,7 @@ appendNodes (Node t1 n1) (Node t2 n2)
3341-- | Type used to represent a directed graph
3442--
3543newtype DirectedGraph a = DirectedGraph {unDirectedGraph :: Map a (Node a)}
36− deriving (Show)
44+ deriving (Show, Binary)
3745
3846-- | Allow users to concatenate different graphs
3947--