Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 17 src/Algebra/Graph/Label.hs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,23 @@ instance StarSemiring (Label a) where
star (Star x) = star x
star x = Star x

instance Applicative Label where
pure = Symbol
Zero <*> _ = Zero
One <*> _ = One
(Symbol x) <*> z = fmap x z
(x :+: y) <*> z = (x <*> z) :+: (y <*> z)
(x :*: y) <*> z = (x <*> z) :*: (y <*> z)
(Star x) <*> z = Star (x <*> z)

instance Monad Label where
Zero >>= _ = Zero
One >>= _ = One
(Symbol x) >>= f = f x
(x :+: y) >>= f = (x >>= f) :+: (y >>= f)
(x :*: y) >>= f = (x >>= f) :*: (y >>= f)
(Star x) >>= f = Star (x >>= f)

-- | Check if a 'Label' is 'zero'.
isZero :: Label a -> Bool
isZero Zero = True
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.