Skip to main content

All Questions

Tagged with
1 vote
1 answer
104 views

Showing Functor result in Haskell

I have defined the following Functor with the following type class ... -- Let's suppose we want to create a functor that -- performs the opperation : -- -- fmap inc (Strength 3) data Stat a = ...
Yago's user avatar
  • 427
3 votes
1 answer
120 views

I can't derive the type of fmap . const

While studying Haskell, I learned that <$ is defined as (<$) = fmap . const. I wanted to understand this by deriving its type and behavior from fmap, const, and (.). However, no matter how much ...
csh's user avatar
  • 85
1 vote
2 answers
103 views

Is there a data type with two Functor instances and two Applicative instances, the latter with either 1 pure and 2 ap or vice-versa?

I came across this answer, where the claim that A Functor instance is unique left me a bit puzzled. Ok, I think [] can be a Functor only in 1 way, but (,) can surely be made a Functor in 2 symmetric ...
Enlico's user avatar
  • 28.9k
1 vote
1 answer
149 views

Why can't MSet be an instance of Functor?

I am working with a custom data type MSet that represents a multiset. The multiset is defined as: data MSet a = MSet [(a, Int)] Where each tuple (a, Int) represents an element a and its multiplicity (...
Daniele Caliandro's user avatar
5 votes
1 answer
109 views

Trouble understanding Haskell type unification with a nested `fmap`

I came across this problem while looking at free monads, but have brought it down to a much smaller example. In Haskell we have the following type: fmap :: Functor f => (a -> b) -> f a -> ...
Piturnah's user avatar
  • 626
1 vote
0 answers
44 views

How to restrict the type of an instance when the instance requires a "* -> *" type in Haskell? [duplicate]

I'm trying to design a type that holds some value and keeps track of all operations done upon it. It does this by storing them in string format (this is not for a project, just learning) I tried to ...
SHIPWECK's user avatar
  • 109
1 vote
1 answer
135 views

Constructor classes: why not mention the content's type?

Following on from this q about monad transformers ... Before constructor classes were introduced [M.P.Jones 1993], Haskell class decls: Must have a single parameter; That parameter must be kind Type (...
AntC's user avatar
  • 2,806
4 votes
3 answers
184 views

How does <$ = (fmap . const) in Functor even work in Haskell?

I know that the dot (.) operator takes two functions which both take an argument respectively, and the third argument for the second argument. Its type is (.) :: (b -> c) -> (a -> b) -> a -...
Akari's user avatar
  • 155
1 vote
1 answer
116 views

How to deal with Monad, Functor and Applicative in order to write stateful code

I am attempting to write some stateful code in Haskell. To this end, I follow this material. At this point, I got my way to monads and functors, and, roughly put, I am confused and can't make progress ...
coderodde's user avatar
  • 997
12 votes
3 answers
805 views

Every Lens' is a Traversal'... how?

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 ...
cobra's user avatar
  • 579
-1 votes
1 answer
93 views

Making a function an instance of functor

I'm attempting to implement functor for a record object that has a function attribute, something like this: data Function a = Function { , funcApply :: FData -> [Exp a] -> Either (...
Chris J Harris's user avatar
0 votes
1 answer
124 views

Haskell Error: Expected kind ‘* -> *’, but ‘Movie’ has kind ‘*’

I created a "Movie" algebraic data type (as requested by the task): data Movie = Movie { title :: String, director :: String, releaseYear :: Int} Then added a functor: instance Functor ...
EvilROMA's user avatar
0 votes
4 answers
150 views

Functor over multiple levels

I have this lame attempt: fmap2 :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) fmap2 f f2 = (fmap2 f . fmap f2) It is supposed to work like this: fmap2 negate [[1,2], [3]] -- ...
coderodde's user avatar
  • 997
3 votes
1 answer
152 views

Can we always use <$> in Haskell to define functions "point free"?

I have been learning just how powerful the <$> and <*> operators are in Haskell, and how it is possible to define some functions without parameters where they would normally be needed. I ...
FuzzyCat444's user avatar
7 votes
1 answer
229 views

Is this "Coapplicative" class a superclass for Comonad?

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 ...
Dannyu NDos's user avatar
  • 2,518

15 30 50 per page
1
2 3 4 5
33