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 8153241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:57:11+00:00 2026-06-06T15:57:11+00:00

I am attempting to implement the Functor fmap over a Data.Map.Map, but I am

  • 0

I am attempting to implement the Functor fmap over a Data.Map.Map, but I am getting an error. I’m sure I don’t need to convert the Map to and from a List in order to get this working, but this is the best I’ve come up with so far.

class Functor' f where
    fmap' :: (a -> b) -> f a -> f b

instance Functor' (Map.Map k) where
    fmap' f m
        | Map.null m = Map.empty
        | otherwise = let x:xs = Map.toList m
                          mtail = Map.fromList xs
                          a = fst x
                          b = snd x
                      in  Map.insert a (f b) (fmap f mtail)

The error:

No instance for (Ord k)
  arising from a use of `Map.fromList'
In the expression: Map.fromList xs
In an equation for `mtail': mtail = Map.fromList xs
In the expression:
  let
    x : xs = Map.toList m
    mtail = Map.fromList xs
    a = fst x
    ....
  in Map.insert a (f b) (fmap f mtail)

Any ideas?

  • 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-06-06T15:57:14+00:00Added an answer on June 6, 2026 at 3:57 pm

    The error is due to not assigning the Ord predicate to the type-variable k. Just do this:

    instance Ord k => Functor' (Map.Map k) where
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently attempting to implement a custom gridview interface to display data from
I'm attempting to implement the technique for data validation from Josh Smith's example here:
Scenario I am attempting to implement supervised learning over a data set within a
I saw connected topic but... I was attempting to implement specification pattern. If I
I'm attempting to implement a repository pattern with my poco objects auto generated from
I am attempting to implement the jQuery Tools Scrollable Example from here: http://flowplayer.org/tools/scrollable/index.html and
Im attempting to implement an RSA encryption algorithm into my iOS app, but when
I am attempting to implement a reverse proxy using the RequestInterceptor from WCF REST
I'm attempting to implement quicksort in-place, using boost's threading facility. Unfortunately I'm getting an
I'm attempting to implement a simple Box Blur, but am having issues. Namely, instead

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.