question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add spec for Alt, Plus, Alternative

See original GitHub issue

I think it would be nice if we also define algebras for Alt, Plus and Alternative

-- | The `Alt` type class identifies an associative operation on a type
-- | constructor.  It is similar to `Semigroup`, except that it applies to
-- | types of kind `* -> *`, like `Array` or `List`, rather than concrete types
-- | `String` or `Number`.
-- |
-- | `Alt` instances are required to satisfy the following laws:
-- |
-- | - Associativity: `(x <|> y) <|> z == x <|> (y <|> z)`
-- | - Distributivity: `f <$> (x <|> y) == (f <$> x) <|> (f <$> y)`
-- |
-- | For example, the `Array` (`[]`) type is an instance of `Alt`, where
-- | `(<|>)` is defined to be concatenation.
class Functor f <= Alt f where
  alt :: forall a. f a -> f a -> f a


-- | The `Plus` type class extends the `Alt` type class with a value that
-- | should be the left and right identity for `(<|>)`.
-- |
-- | It is similar to `Monoid`, except that it applies to types of
-- | kind `* -> *`, like `Array` or `List`, rather than concrete types like
-- | `String` or `Number`.
-- |
-- | `Plus` instances should satisfy the following laws:
-- |
-- | - Left identity: `empty <|> x == x`
-- | - Right identity: `x <|> empty == x`
-- | - Annihilation: `f <$> empty == empty`
class Alt f <= Plus f where
  empty :: forall a. f a


-- | The `Alternative` type class has no members of its own; it just specifies
-- | that the type constructor has both `Applicative` and `Plus` instances.
-- |
-- | Types which have `Alternative` instances should also satisfy the following
-- | laws:
-- |
-- | - Distributivity: `(f <|> g) <*> x == (f <*> x) <|> (g <*> x)`
-- | - Annihilation: `empty <*> f = empty`
class (Applicative f, Plus f) <= Alternative f

Snippets from purescript-control

It will be useful to Future/Task implementations (alt will be race). and with also define Parallel algebra then in concurrent applicative could implement Alternative and we would have the race as well (MonadRace is removed).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:25 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
safarelicommented, Oct 24, 2016

@joneshf correct ! (I had a mistake in graph)

here is updated one: screen shot 2016-10-24 at 6 45 16 pm

2reactions
joneshfcommented, Oct 24, 2016

I think that’s asking too much of Alt and Plus. For instance, something like data Map k v = ... doesn’t have a sensible Applicative instance for Map k. However, you should be able to write an Alt instance for Map k, assuming Ord k of course. It’s better to have Functor be the superclass of Alt

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get special characters using Alt key codes or the Word ...
Open a Word file, select Insert > Symbol, scroll down to the new font, choose one of the symbols, and click Insert. Notice...
Read more >
The Ultimate List of Helpful Windows Alt Codes to Insert ...
Shortcut Character Unicode Description Alt + 1 ☺ Smiley Face Alt + 2 ☻ Dark Smiley Face Alt + 3 ♥ Heart
Read more >
Alt Codes List of Alt Key Codes Symbols
The list of all Alt Codes for special characters and symbols. Learn How to use Alt Key Codes? for special characters and symbols....
Read more >
Alt Codes – How to Type Special Characters and Keyboard ...
In Windows, you can type any character you want by holding down the ALT key, typing a sequence of numbers, then releasing the...
Read more >
ALT Codes for Special Characters, Signs & Symbols
Character ALT Code Unicode Code Point Character ALT Code Unicode Code Point ␀ ALT 0 U+0000 ␀ ALT 0 U+0000 ALT 1 U+263A ␁ ALT...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found