All Questions
495 questions
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 = ...
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 ...
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 ...
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 (...
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 -> ...
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 ...
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 (...
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 -...
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 ...
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 ...
-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 (...
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 ...
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]] -- ...
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 ...
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 ...