alternative-functor Questions

3

Solved

I am a Haskell newbie and I wonder why there is no alternative instance for Either but a semigroup, which behaves as I would expect it from alternative: instance Semigroup (Either a b) where Left ...
Maidstone asked 10/6, 2017 at 10:1

3

Solved

I recently wrote do e <- (Left <$> m) <|> (Right <$> n) more actions case e of Left x -> ... Right y -> ... This seems awkward. I know that protolude (and some othe...
Punchdrunk asked 24/1, 2022 at 21:29

2

I declared a group on applicative functors. Judging by what we usually call "actions", it seems that such group would enable the action to be undone: import Control.Applicative class Alt...
Frodeen asked 8/10, 2021 at 2:47

5

Solved

Alternative, an extension of Applicative, declares empty, <|> and these two functions: One or more: some :: f a -> f [a] Zero or more: many :: f a -> f [a] If defined, some...
Accentor asked 7/8, 2013 at 16:23

1

Solved

A few times now, I've found myself defining: (<?>) :: [a] -> [a] -> [a] [] <?> ys = ys xs <?> _ = xs This is an associative operation, of course, and the empty list [] is...

1

Solved

The category of sets is both cartesian monoidal and cocartesian monoidal. The types of the canonical isomorphisms witnessing these two monoidal structures are listed below: type x + y = Either x y...

3

Solved

I am trying to get a firm grasp of exceptions, so that I can improve my conditional loop implementation. To this end, I am staging various experiments, throwing stuff and seeing what gets caught. ...
Emory asked 7/8, 2019 at 19:58

1

We can define the continuation monad transformer as data Cont r m a = Cont {run :: (a -> m r) -> m r} We can give Cont r m an Alternative instance if m is a member of Alternative via empt...

4

Solved

ZipList comes with a Functor and an Applicative instance (Control.Applicative) but why not Alternative? Is there no good instance? What about the one proposed below? Is it flawed? is it useles...
Myrlemyrlene asked 13/8, 2013 at 13:42

1

Solved

There is a nice Free Alternative in the great free package, which lifts a Functor to a left-distributive Alternative. That is, the claim is that: runAlt :: Alternative g => (forall x. f x -&gt...

1

Solved

Why is guard based on Alternative? guard :: Alternative f => Bool -> f () -- guard b is pure () if b is True, -- and empty if b is False. I ask because guard only uses the empty from Alter...
Laundry asked 22/6, 2017 at 10:35

2

Solved

The following typechecks: instance (Applicative f, Alternative f, Foldable f) => Monad f where (>>=) = flip $ \f -> foldr (<|>) empty . fmap f -- Or equivalently a >>= ...
Deyo asked 24/5, 2017 at 11:19

1

I am currently reading about the Alternative/MonadPlus typeclasses in wikibooks. It describes the difference very well. However, one puzzling part is the guard function, which I am assuming, is use...
Sajovich asked 4/2, 2017 at 5:59

2

Control.Applicative.optional allows to handle zero or one Applicatives. many & some allow for 0 or more, or 1 or more, respectively. I'd like to create a function that handles zero, one or two,...
Vincenz asked 25/9, 2016 at 19:18

3

Solved

I just found myself writing this code: import Control.Applicative ((<|>)) x = mA <|> mB <?> c (<?>) :: Maybe a -> a -> a Just x <?> _ = x Nothing <?> y ...
Escobedo asked 29/8, 2016 at 8:54

1

Is there an established name for maybe mzero return? It has the type: MonadPlus m => Maybe a -> m a and converts Nothing to failure and Just a to return a.
Heddle asked 17/5, 2016 at 1:52

3

Solved

I was just writing a quick bit of code, and I wanted to use the guard function in the IO Monad. However, there is no definition of MonadPlus for IO which means that we cannot use guard in IO land. ...
Hide asked 21/12, 2010 at 22:18

1

Solved

Consider the following type signatures: data Foo x = Foo { name :: String , reader :: String -> x } instance Functor Foo where fmap f (Foo n r) = Foo n $ f . r Now I show a natural transf...

1

Solved

I have a couple of snippets which feel like they're doing the same thing, but I'm not entirely convinced there is a generalised construct to handle them both. In one place, I have ensure :: (Strin...
Curfew asked 4/12, 2015 at 13:30

1

Solved

I read Why MonadPlus and not Monad + Monoid? and I understand a theoretical difference, but I cannot figure out a practical difference, because for List it looks the same. mappend [1] [2] == [1] &...
Dreda asked 2/8, 2015 at 9:59

1

Solved

Haskell provides a standard typeclass 'Alternative' that effectively provides the <|> operator for any type that is also an Applicative. As I understand it Alternative is considered a Monoid...
Virgil asked 27/5, 2015 at 11:25

1

Solved

It appears that type classes such as Applicative, Monad and Arrow have some sort of sum type equivalent in type classes such as Alternative, MonadPlus and ArrowPlus respectively. For example, Appli...

1

Solved

There is an instance Monoid a => Monoid (Const a b) for the Const functor from Control.Applicative. There is also an instance Monoid m => Applicative (Const m). I would therefore expect tha...
Ekg asked 23/2, 2015 at 18:56

4

Solved

Going through Haskell's documentation is always a bit of a pain for me, because all the information you get about a function is often nothing more than just: f a -> f [a] which could mean any nu...
Condonation asked 23/9, 2014 at 18:39

3

Solved

Applicative functors are well-known and well-loved among Haskellers, for their ability to apply functions in an effectful context. In category-theoretic terms, it can be shown that the methods of ...

© 2022 - 2025 — McMap. All rights reserved.