foldable Questions
3
I'm working through the wonderful Haskell Book. At the end of the Traversable chapter (21), I need to write an instance for the following Tree:
data Tree a =
Empty
| Leaf a
| Node (Tree a) a (Tr...
Canady asked 1/1, 2021 at 19:56
0
Despite the jargon filled title I don't think this question is very complex.
Introducing the characters
There are two important Functor combinators at play here. Flip equivalent to the haskell func...
Capsulize asked 23/8, 2020 at 2:55
3
Solved
I'm experimenting with the Foldable typeclass in Haskell, using the following data type as an example:
data Tree a = Empty
| Node (Tree a) a (Tree a)
If I use the DeriveFoldable GHC extension, ...
1
Solved
While looking at the definition of Monoid I noticed that mconcat has the following definition (source):
mconcat :: Monoid a => [a] -> a
mconcat = foldr mappend mempty
Why would the signatu...
2
I have just started learning Haskell. As I know maximum gives the max value for a list of integers. So, maximum [2,5,7,1] gives 7. But why by giving a tuple input does maximum always give the...
2
Solved
Can someone explain what the type mean and how to implement this?
class Foldable f where
foldMap :: (Monoid m) => (a -> m) -> f a -> m
Based on https://hackage.haskell.org/package/b...
3
Solved
2
Solved
I recently read about recursion schemes where catamorphisms are described as analogous to generalized foldr.
Is is possible to write an instance of Foldable (via either foldr or foldMap) in terms...
Hoopen asked 1/8, 2019 at 8:52
3
class (Functor t, Foldable t) => Traversable t where
traverse :: Applicative f => (a -> f b) -> t a -> f (t b)
traverse g = sequenceA . fmap g
sequenceA :: Applicative f => t...
Pluckless asked 30/7, 2019 at 4:1
2
Solved
I am trying to understand Traversable with the help of https://namc.in/2018-02-05-foldables-traversals.
Somewhere the author mentioned the following sentence:
Traversable is to Applicative con...
Viperish asked 5/4, 2019 at 10:19
4
Solved
I would like to express the following Haskell code, using only functor algebra (i.e. - not relying on any specific container type, such as List):
ys = zipWith (+) (head xs : repeat 0)
(tail xs ++...
Doriedorin asked 10/6, 2018 at 15:27
1
Solved
For me, an integer set seems to be a foldable data structure.
Why is Data.IntSet not an instance of Foldable?
My actual intention is to use find on an IntSet.
How can I implement find for Data.Int...
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
Solved
We know fmap is fmap :: Functor f => (a -> b) -> f a -> f b and sum is sum :: (Num a, Foldable t) => t a -> a, but the code below confuse me.
> :t (fmap sum Just)
(fmap sum Ju...
1
Solved
first question here and completely a noob on haskell, so please be kind with me :)
I was playing with the question number 6 of this haskell exercises
and in the end came to the solution (or somet...
3
Consider the following signature of foldMap
foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m
This is very similar to "bind", just with the arguments swapped:
(>>=) ::...
Out asked 10/10, 2016 at 5:27
2
MonoFoldable in the mono-traversable package seems to be able to implement all of the usual Foldable containers and more, for example, things like Bytestring and homogeneous tuples can be made Mono...
Guttapercha asked 22/9, 2016 at 8:56
1
Solved
I am looking at the Foldable class in Haskell. Two of the methods fold, foldMap requires a Monoid instance. But foldr or foldl don't have any such constraint.
fold :: Monoid m => t m -> m
fo...
1
Solved
While studying Applicative deeper, I came to Traversable. Although I already knew Foldable from LYHGG, I haven't seen the former yet, so I started reading the Haskell wiki about Traversable.
While...
Confabulation asked 8/3, 2016 at 2:18
1
Solved
data Tree t = Empty | Node t (Tree t) (Tree t)
We can create Functor instance and use
fmap :: (t -> a) -> Tree t -> Tree a
But what if instead of (t -> a) I want (Tree t -> a) so I co...
1
Solved
I'm playing around with type-aligned sequences, and in particular I'm messing around with the idea of folding them. A foldable type-aligned sequence looks something like this:
class FoldableTA fm ...
Barite asked 22/6, 2015 at 16:23
2
Solved
I am a beginner at Haskell and learning from "Learn You a Haskell".
There's something I don't understand about the Tree implementation of Foldable.
instance F.Foldable Tree where
foldMap f Empt...
1
© 2022 - 2024 — McMap. All rights reserved.