Is it possible to make a Functor instance for a type parameter other than the last? [duplicate]Can I write a higher order type for a -> b -> *?Monad instance for pairsAre there “type-level combinators”? Will they exist in some future?Haskell defining Functor instance for an alternative Either data typeLarge-scale design in Haskell?Functor / Applicative instances for State in HaskellWhat functionality do you get for free with Functors or other type-classes?Deriving functor instance, not on last type argumentCan this multi-parameter type class be simplified?Understanding operations on composed functor typesHow to create Functor definition for Either typeIs this property of a functor stronger than a monad?How do I make the partially-applied function type into a functor?What does instance mean in Haskell?

Why is “deal 6 damage” a legit phrase?

Error with uppercase in titlesec's label field

Normally Closed Optoisolators

"Will flex for food". What does this phrase mean?

How do I safety check that there is no light in Darkroom / Darkbag?

Why are sugars in whole fruits not digested the same way sugars in juice are?

Why should I use a big powerstone instead of smaller ones?

Adjective for when skills are not improving and I'm depressed about it

A game of red and black

Is it really a problem to declare that a visitor to the UK is my "girlfriend", in terms of her successfully getting a Standard Visitor visa?

Went to a big 4 but got fired for underperformance in a year recently - Now every one thinks I'm pro - How to balance expectations?

When did J.K. Rowling decide to make Ron and Hermione a couple?

How did Biff return to 2015 from 1955 without a lightning strike?

Word for giving preference to the oldest child

How do I respond appropriately to an overseas company that obtained a visa for me without hiring me?

Can birds evolve without trees?

Should I put my name first or last in the team members list?

Using Python in a Bash Script

How to define a functional that produces at runtime a function by evaluating selected parts in its definition?

The grades of the students in a class

Why do we need a voltage divider when we get the same voltage at the output as the input?

Should 2FA be enabled on service accounts?

PI 4 screen rotation from the terminal

Basic transistor circuit



Is it possible to make a Functor instance for a type parameter other than the last? [duplicate]


Can I write a higher order type for a -> b -> *?Monad instance for pairsAre there “type-level combinators”? Will they exist in some future?Haskell defining Functor instance for an alternative Either data typeLarge-scale design in Haskell?Functor / Applicative instances for State in HaskellWhat functionality do you get for free with Functors or other type-classes?Deriving functor instance, not on last type argumentCan this multi-parameter type class be simplified?Understanding operations on composed functor typesHow to create Functor definition for Either typeIs this property of a functor stronger than a monad?How do I make the partially-applied function type into a functor?What does instance mean in Haskell?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1
















This question already has an answer here:



  • Can I write a higher order type for a -> b -> *?

    1 answer



  • Monad instance for pairs

    2 answers



Sometimes there are data types that contain multiple type parameters (eg Either a b and (a,b)). We can create a Functor instance for the b parameter which turns out to be pretty straight forward. But what about the a parameter? I know that one could wrap everything in a newtype with the parameters in reverse order, but is there a way to create the instance of a second order type class (is that the correct way to describe Functor/ Applicative / Monad?) directly on a parameter other than the last? I don't think so but I could not actually find that written down anywhere.



Context:



Another question on Stack Overflow was from a student studying Haskell who was trying to create a Functor instance for their own Either-like Type presumably as a class assignment. Unfortunately, they had defined their data type as data Alt a b = Success a | Failure b and could not get the functor instance to work because they wanted to fmap over the a parameter. I was about to write that Functor instances only work for the last parameter when I realized that I did not actually know that for sure. Thus my question.










share|improve this question
















marked as duplicate by jberryman, Daniel Wagner haskell
Users with the  haskell badge can single-handedly close haskell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 0:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 2





    well there are always Bifunctors - you could define a new typeclass which just included first from Bifunctor (presumably under some other name). I think the only reason the last parameter is "privileged" in the way you describe is that type application (like function application) is left-associative - so Either a b is the same as (Either a) b, and can't be rewritten as something applied to a (without some newtype shenanigans as you observe).

    – Robin Zigmond
    Mar 26 at 23:40






  • 1





    Also related: Are there “type-level combinators”? Will they exist in some future?

    – duplode
    Mar 26 at 23:53











  • I don't think this is actually an exact duplicate of either of the linked questions.

    – Benjamin Hodgson
    Mar 27 at 15:21






  • 1





    @John F. Miller: I asked the original questions. Benjamin Hodgson, Chepner and Daniel Wagner provided lots of useful information. I learned a lot from their comments in combination with getting my head around the Typeclassopedia. I am still a long way from the level of understanding these guys have of Haskell, but it nonetheless it fuels my enthousiasm to dive in deeper and deeper ;-)

    – Madderote
    Mar 27 at 19:14

















1
















This question already has an answer here:



  • Can I write a higher order type for a -> b -> *?

    1 answer



  • Monad instance for pairs

    2 answers



Sometimes there are data types that contain multiple type parameters (eg Either a b and (a,b)). We can create a Functor instance for the b parameter which turns out to be pretty straight forward. But what about the a parameter? I know that one could wrap everything in a newtype with the parameters in reverse order, but is there a way to create the instance of a second order type class (is that the correct way to describe Functor/ Applicative / Monad?) directly on a parameter other than the last? I don't think so but I could not actually find that written down anywhere.



Context:



Another question on Stack Overflow was from a student studying Haskell who was trying to create a Functor instance for their own Either-like Type presumably as a class assignment. Unfortunately, they had defined their data type as data Alt a b = Success a | Failure b and could not get the functor instance to work because they wanted to fmap over the a parameter. I was about to write that Functor instances only work for the last parameter when I realized that I did not actually know that for sure. Thus my question.










share|improve this question
















marked as duplicate by jberryman, Daniel Wagner haskell
Users with the  haskell badge can single-handedly close haskell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 0:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 2





    well there are always Bifunctors - you could define a new typeclass which just included first from Bifunctor (presumably under some other name). I think the only reason the last parameter is "privileged" in the way you describe is that type application (like function application) is left-associative - so Either a b is the same as (Either a) b, and can't be rewritten as something applied to a (without some newtype shenanigans as you observe).

    – Robin Zigmond
    Mar 26 at 23:40






  • 1





    Also related: Are there “type-level combinators”? Will they exist in some future?

    – duplode
    Mar 26 at 23:53











  • I don't think this is actually an exact duplicate of either of the linked questions.

    – Benjamin Hodgson
    Mar 27 at 15:21






  • 1





    @John F. Miller: I asked the original questions. Benjamin Hodgson, Chepner and Daniel Wagner provided lots of useful information. I learned a lot from their comments in combination with getting my head around the Typeclassopedia. I am still a long way from the level of understanding these guys have of Haskell, but it nonetheless it fuels my enthousiasm to dive in deeper and deeper ;-)

    – Madderote
    Mar 27 at 19:14













1












1








1









This question already has an answer here:



  • Can I write a higher order type for a -> b -> *?

    1 answer



  • Monad instance for pairs

    2 answers



Sometimes there are data types that contain multiple type parameters (eg Either a b and (a,b)). We can create a Functor instance for the b parameter which turns out to be pretty straight forward. But what about the a parameter? I know that one could wrap everything in a newtype with the parameters in reverse order, but is there a way to create the instance of a second order type class (is that the correct way to describe Functor/ Applicative / Monad?) directly on a parameter other than the last? I don't think so but I could not actually find that written down anywhere.



Context:



Another question on Stack Overflow was from a student studying Haskell who was trying to create a Functor instance for their own Either-like Type presumably as a class assignment. Unfortunately, they had defined their data type as data Alt a b = Success a | Failure b and could not get the functor instance to work because they wanted to fmap over the a parameter. I was about to write that Functor instances only work for the last parameter when I realized that I did not actually know that for sure. Thus my question.










share|improve this question

















This question already has an answer here:



  • Can I write a higher order type for a -> b -> *?

    1 answer



  • Monad instance for pairs

    2 answers



Sometimes there are data types that contain multiple type parameters (eg Either a b and (a,b)). We can create a Functor instance for the b parameter which turns out to be pretty straight forward. But what about the a parameter? I know that one could wrap everything in a newtype with the parameters in reverse order, but is there a way to create the instance of a second order type class (is that the correct way to describe Functor/ Applicative / Monad?) directly on a parameter other than the last? I don't think so but I could not actually find that written down anywhere.



Context:



Another question on Stack Overflow was from a student studying Haskell who was trying to create a Functor instance for their own Either-like Type presumably as a class assignment. Unfortunately, they had defined their data type as data Alt a b = Success a | Failure b and could not get the functor instance to work because they wanted to fmap over the a parameter. I was about to write that Functor instances only work for the last parameter when I realized that I did not actually know that for sure. Thus my question.





This question already has an answer here:



  • Can I write a higher order type for a -> b -> *?

    1 answer



  • Monad instance for pairs

    2 answers







haskell typeclass






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 2:22









duplode

26.7k4 gold badges54 silver badges104 bronze badges




26.7k4 gold badges54 silver badges104 bronze badges










asked Mar 26 at 23:34









John F. MillerJohn F. Miller

17.3k8 gold badges57 silver badges109 bronze badges




17.3k8 gold badges57 silver badges109 bronze badges





marked as duplicate by jberryman, Daniel Wagner haskell
Users with the  haskell badge can single-handedly close haskell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 0:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











marked as duplicate by jberryman, Daniel Wagner haskell
Users with the  haskell badge can single-handedly close haskell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 0:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by jberryman, Daniel Wagner haskell
Users with the  haskell badge can single-handedly close haskell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 0:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 2





    well there are always Bifunctors - you could define a new typeclass which just included first from Bifunctor (presumably under some other name). I think the only reason the last parameter is "privileged" in the way you describe is that type application (like function application) is left-associative - so Either a b is the same as (Either a) b, and can't be rewritten as something applied to a (without some newtype shenanigans as you observe).

    – Robin Zigmond
    Mar 26 at 23:40






  • 1





    Also related: Are there “type-level combinators”? Will they exist in some future?

    – duplode
    Mar 26 at 23:53











  • I don't think this is actually an exact duplicate of either of the linked questions.

    – Benjamin Hodgson
    Mar 27 at 15:21






  • 1





    @John F. Miller: I asked the original questions. Benjamin Hodgson, Chepner and Daniel Wagner provided lots of useful information. I learned a lot from their comments in combination with getting my head around the Typeclassopedia. I am still a long way from the level of understanding these guys have of Haskell, but it nonetheless it fuels my enthousiasm to dive in deeper and deeper ;-)

    – Madderote
    Mar 27 at 19:14












  • 2





    well there are always Bifunctors - you could define a new typeclass which just included first from Bifunctor (presumably under some other name). I think the only reason the last parameter is "privileged" in the way you describe is that type application (like function application) is left-associative - so Either a b is the same as (Either a) b, and can't be rewritten as something applied to a (without some newtype shenanigans as you observe).

    – Robin Zigmond
    Mar 26 at 23:40






  • 1





    Also related: Are there “type-level combinators”? Will they exist in some future?

    – duplode
    Mar 26 at 23:53











  • I don't think this is actually an exact duplicate of either of the linked questions.

    – Benjamin Hodgson
    Mar 27 at 15:21






  • 1





    @John F. Miller: I asked the original questions. Benjamin Hodgson, Chepner and Daniel Wagner provided lots of useful information. I learned a lot from their comments in combination with getting my head around the Typeclassopedia. I am still a long way from the level of understanding these guys have of Haskell, but it nonetheless it fuels my enthousiasm to dive in deeper and deeper ;-)

    – Madderote
    Mar 27 at 19:14







2




2





well there are always Bifunctors - you could define a new typeclass which just included first from Bifunctor (presumably under some other name). I think the only reason the last parameter is "privileged" in the way you describe is that type application (like function application) is left-associative - so Either a b is the same as (Either a) b, and can't be rewritten as something applied to a (without some newtype shenanigans as you observe).

– Robin Zigmond
Mar 26 at 23:40





well there are always Bifunctors - you could define a new typeclass which just included first from Bifunctor (presumably under some other name). I think the only reason the last parameter is "privileged" in the way you describe is that type application (like function application) is left-associative - so Either a b is the same as (Either a) b, and can't be rewritten as something applied to a (without some newtype shenanigans as you observe).

– Robin Zigmond
Mar 26 at 23:40




1




1





Also related: Are there “type-level combinators”? Will they exist in some future?

– duplode
Mar 26 at 23:53





Also related: Are there “type-level combinators”? Will they exist in some future?

– duplode
Mar 26 at 23:53













I don't think this is actually an exact duplicate of either of the linked questions.

– Benjamin Hodgson
Mar 27 at 15:21





I don't think this is actually an exact duplicate of either of the linked questions.

– Benjamin Hodgson
Mar 27 at 15:21




1




1





@John F. Miller: I asked the original questions. Benjamin Hodgson, Chepner and Daniel Wagner provided lots of useful information. I learned a lot from their comments in combination with getting my head around the Typeclassopedia. I am still a long way from the level of understanding these guys have of Haskell, but it nonetheless it fuels my enthousiasm to dive in deeper and deeper ;-)

– Madderote
Mar 27 at 19:14





@John F. Miller: I asked the original questions. Benjamin Hodgson, Chepner and Daniel Wagner provided lots of useful information. I learned a lot from their comments in combination with getting my head around the Typeclassopedia. I am still a long way from the level of understanding these guys have of Haskell, but it nonetheless it fuels my enthousiasm to dive in deeper and deeper ;-)

– Madderote
Mar 27 at 19:14












0






active

oldest

votes














0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.





Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현