Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6770359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:18:10+00:00 2026-05-26T15:18:10+00:00

Consider the following type: data SomeType m a = SomeType (m Integer) [a] We

  • 0

Consider the following type:

data SomeType m a = SomeType (m Integer) [a]

We can easily make that type an instance of Functor with the following code:

instance Functor (SomeType m) where
  fmap f (SomeType m lst) = SomeType m (map f lst)

However, if instead the params of the SomeType type were swapped:

data SomeType2 a m = SomeType2 (m Integer) [a]

Then the above instance definition doesn’t work.

Is there some way of making SomeType2 an instance of Functor? If not, are there any up and coming additions to haskell/ghc that would make it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:18:11+00:00Added an answer on May 26, 2026 at 3:18 pm

    Biased am I, but I think this is a great opportunity to make use of Control.Newtype, a little piece of kit that’s a mere “cabal install newtype” away.

    Here’s the deal. You want to flip around type constructors to get your hands on functoriality (for example) in a different parameter. Define a newtype

     newtype Flip f x y = Flip (f y x)
    

    and add it to the Newtype class thus

     instance Newtype (Flip f x y) (f y x) where
       pack = Flip
       unpack (Flip z) = z
    

    The Newtype class is just a directory mapping newtypes to their unvarnished equivalents, providing handy kit, e.g. op Flip is the inverse of Flip: you don’t need to remember what you called it.

    For the problem in question, we can now do stuff like this:

     data Bif x y = BNil | BCons x y (Bif x y) deriving Show
    

    That’s a two parameter datatype which happens to be functorial in both parameters. (Probably, we should make it an instance of a Bifunctor class, but anyway…) We can make it a Functor twice over: once for the last parameter…

    instance Functor (Bif x) where
      fmap f BNil = BNil
      fmap f (BCons x y b) = BCons x (f y) (fmap f b)
    

    …and once for the first:

    instance Functor (Flip Bif y) where
      fmap f (Flip BNil) = Flip BNil
      fmap f (Flip (BCons x y b)) = Flip (BCons (f x) y (under Flip (fmap f) b))
    

    where under p f is a neat way to say op p . f . p.

    I tell you no lies: let us try.

    someBif :: Bif Int Char
    someBif = BCons 1 'a' (BCons 2 'b' (BCons 3 'c' BNil))
    

    and then we get

    *Flip> fmap succ someBif
    BCons 1 'b' (BCons 2 'c' (BCons 3 'd' BNil))
    *Flip> under Flip (fmap succ) someBif
    BCons 2 'a' (BCons 3 'b' (BCons 4 'c' BNil))
    

    In these circumstances, there really are many ways the same thing can be seen as a Functor, so it’s right that we have to make some noise to say which way we mean. But the noise isn’t all that much if you’re systematic about it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: require(Hmisc) num.boots <- 10 data <- rchisq(500, df = 5)
Consider the following piece of code: class B { private: // some data members
OLEDB can be used to read and write Excel sheets. Consider the following code
Consider the following data Predicate = Pred Name Arity Arguments type Name = String
Consider the following code, data MyBaseExpr α where ConstE :: Show α => α
Consider the following nested type: public class Book { private class Chapter { }
Consider my first attempt, a simple type in F# like the following: type Test()
Consider the following table: mysql> select * from phone_numbers; +-------------+------+-----------+ | number | type
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.