functor Questions

3

Solved

Control.Lens.Tutorial says: type Traversal' a b = forall f . Applicative f => (b -> f b) -> (a -> f a) type Lens' a b = forall f . Functor f => (b -> f b) -> (a -> f a) ...
Avulsion asked 21/2, 2024 at 14:5

3

Solved

During play around objective package, I noticed following type has interesting property. > {-# LANGUAGE RankNTypes #-} > data N f r = N { unN :: forall x. f x -> (x, r) } It is a Functo...
Compress asked 29/4, 2016 at 3:23

6

I am getting into Haskell and found the book "learn you a Haskell" most helpful. I am up to the section on applicative functors. I am puzzled by the following as it appears in the book: (\x y z ...
Separator asked 27/1, 2014 at 8:31

1

Recall the Applicative class: class Functor f => Applicative f where pure :: a -> f a liftA2 :: (a -> b -> c) -> f a -> f b -> f c (<*>) :: f (a -> b) -> f a -&g...
Rybinsk asked 26/8, 2023 at 6:28

5

Solved

The free monoids are often being regarded as "list monoids". Yet, I am interested in other possible structures which might give us free monoids. Firstly, let us go over the definition of ...
Sheya asked 16/9, 2020 at 20:57

19

Solved

I've come across the term 'Functor' a few times while reading various articles on functional programming, but the authors typically assume the reader already understands the term. Looking around on...
Deroo asked 8/1, 2010 at 21:26

3

Solved

After looking up the Control.Monad documentation, I'm confused about this passage: The above laws imply: fmap f xs = xs >>= return . f How do they imply that?
Surgical asked 22/5, 2017 at 5:52

5

Solved

Suppose I have a method def doSomething: String which can raise a DoSomethingException if something goes wrong. If I write Try(doSomething), is there a simple way to map the exception without reco...
Stringboard asked 13/12, 2013 at 15:34

2

std::transform from the <algorithm> header applies to ranges, and it is what "enables" us to use ranges as the functors they are (in the sense of category theory(¹)). std::transform...
Igloo asked 9/1, 2022 at 9:58

8

Solved

Why is operator () of stateless functor not allowed to be static? Stateless lambda objects are convertible to pointers to free functions having the same signature as their operator (). Stephan T. ...
Armory asked 25/9, 2015 at 6:53

5

Solved

From categorical point of view, functor is pair of two maps (one between objects and another between arrows of categories), following some axioms. I have assumed, what every Functor instance is si...
Stipulation asked 8/2, 2014 at 15:12

2

Solved

I was kinda surprised when I read the source code of instances of Applicative Complex and Monad Complex from GHC Data.Complex module: -- | @since 4.9.0.0 instance Applicative Complex where pure a...
Stclair asked 8/11, 2017 at 13:32

4

This has me stumped. How do you write a Functor instance for newtype Mu f = InF {outF :: f (Mu f)}
Stansbury asked 29/9, 2016 at 12:20

11

Solved

I'm trying to use a C library in a C++ app and have found my self in the following situation (I know my C, but I'm fairly new to C++). On the C side I have a collection of functions that takes a fu...
Profess asked 3/12, 2009 at 14:2

1

Solved

I started to learn Prolog and I just read that the atom at the beginning of an structure is usually called functor. I'm also familiar with the term functor from Category Theory and Functional Progr...

1

Let's say I have a type that looks like this: data Term a = Terminal a | Application (Term a) (Term a) | Abstraction String (Term a) Now, I want to map Term a to Term b. Ideally, I would be able t...
Kumasi asked 14/5, 2022 at 22:55

12

Solved

In the Boost Signals library, they are overloading the () operator. Is this a convention in C++? For callbacks, etc.? I have seen this in code of a co-worker (who happens to be a big Boost fan). ...

5

Solved

Why does the for_each call on functor doesn't update sum::total at the end? struct sum { sum():total(0){}; int total; void operator()(int element) { total+=element; } }; int main() { s...
Sexist asked 12/3, 2011 at 22:37

5

Solved

I'm quite confused by the behavior of map(). I have an array of objects like this: const products = [{ ..., 'productType' = 'premium', ... }, ...] And I'm passing this array to a function that ...
Mihrab asked 10/3, 2016 at 16:46

1

Solved

I recently discovered how to simulate higher order types in Java in a somewhat roundabout way like so interface H<F, T> { } Here H encodes a higher order type that takes a type parameter F w...

2

Solved

What is the point of making Functor a super class of Applicative and Monad. Both Applicative and Monad immediately imply the only implementation of Functor that abides by the laws as far as I...
Hipster asked 2/1, 2022 at 7:7

5

How can I deduce statically if an argument is a C++ function object (functor)? template <typename F> void test(F f) {} I tried is_function<F>::value, but this doesn't work. It also s...
Kizzie asked 31/1, 2012 at 16:56

2

Bifunctors have a map function with this signature: bimap :: (a -> b) -> (c -> d) -> p a c -> p b d You could also have a map like this: othermap :: ((a, c) -> (b, d)) -> p a...
Jerboa asked 28/12, 2021 at 0:6

1

Solved

I recently defined a type whose fields I might fail to compute: data Foo = Foo {x, y :: Int, others :: NonEmpty Int} data Input computeX, computeY :: Input -> Maybe Int computeOthers :: Input ...
Tabard asked 7/12, 2021 at 10:21

3

Solved

There are similar questions here but they are attached to a particular programming language and I am looking for an answer on the conceptual level. As I understand, Functors are essentially immuta...
Cnidus asked 22/7, 2017 at 9:3

© 2022 - 2025 — McMap. All rights reserved.