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

  • Home
  • SEARCH
  • 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 6065629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:24:42+00:00 2026-05-23T09:24:42+00:00

I would like to have a function for either mapping a pure function to

  • 0

I would like to have a function for either mapping a pure function to a container or sequencing applicative/monadic action through it. For pure mapping we have

fmap :: Functor f => (a -> b) -> (f a -> f b)

For monadic sequencing we have (from Data.Taversable)

mapM :: (Traversable f, Monad m) => (a -> m b) -> (f a -> m (f b))

Which is similar to

mapKleisli :: (Traversable f, Monad m) => Kleisli m a b -> Kleisli m (f a) (f b)
mapKleisli = Kleisli . mapM . runKleisli

We know both (->) and (Kleisli m) are categories (and arrows). So it’s naturally to make a generalization:

mapCategory :: (X f, Category c) => c a b -> c (f a) (f b)

Do you know such a class X with similar method? Maybe, somewhere on hackage? I tried to hoogle/hayoo but haven’t found anything appropriate.

Update:

Now I know better what I need. Both Kleisli arrows and (->) are instances of ArrowApply which is as powerful as Monad. I came up with this arrow-based version of Travesable:

{-# LANGUAGE TypeOperators #-}

import Prelude hiding (id, (.), mapM)
import Control.Arrow
import Control.Category

class Traversable f where
  traverse :: ArrowApply (~>) => f a -> (a ~> b) ~> f b

mapArrow :: (ArrowApply (~>), Traversable f) => a ~> b -> f a ~> f b
mapArrow a = arr (\x -> (traverse x, a)) >>> app

instance Traversable Maybe where
  traverse Nothing = arr (const Nothing)
  traverse (Just x) = arr (\a -> (a, x)) >>> app >>> arr Just

instance Traversable [] where
  traverse [] = arr (const [])
  traverse (x : xs) = undefined -- this is hard!

I could use just usual Applicative-based Traversable, with Identity for pure functions, but I’m not sure it is good. Considering pure functions as special case of monadic actions is weird. Interpreting both pure functions and monadic actions as instances of some action class (Category/Arrow/ArrowApply) looks more straightforward to me.

Questions: would you like to finish instance for []? Has my opinion about ArrowApply vs Monad any sense?

  • 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-23T09:24:43+00:00Added an answer on May 23, 2026 at 9:24 am

    You’re asking for “some class X”, but it should be pretty clear that the most (or perhaps, only) correct name for this class would be “Functor”. What you want is simply a functor class defined for an arbitrary Category instance, rather than limited to (->).

    Of course, your definition is still limited to (endo)functors from a category to a subcategory defined by the type constructor giving the instance. If you generalize a bit further, there’s no reason for the two categories to be the same, giving you a type class something like this one:

    class (Category r, Category t) => Functor f r t | f r -> t, f t -> r where
        fmap :: r a b -> t (f a) (f b)
    

    This is still awfully limited vs. the full concept of a functor in category theory, but oh well.

    It’s also interesting to observe that this still has a (->) type constructor in it–that’s because, even though we’re modeling the source and target categories with arbitrary instances, the whole thing (and in particular, the functor itself) still exists in some sense in Hask, i.e., the category associated with (->). The other half of the functor (the part mapping objects) is, roughly speaking, the (->) in the kind * -> * for the type constructor f.

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

Sidebar

Related Questions

In my UserProfile model I would like to have a function which returns either
I would like to have a function that modifies some variable list of parameters
I would like to have the choice in a variable_load function (as used to
We have a company intranet with staff management functions. I would like to begin
I have a problem that I would like have solved via a SQL query.
I would like to have a reference for the pros and cons of using
I would like to have an iframe take as much vertical space as it
I would like to have a VM to look at how applications appear and
We would like to have user defined formulas in our c++ program. e.g. The
I would like to have a nice template for doing this in development. How

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.