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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:36:32+00:00 2026-05-26T09:36:32+00:00

The simple following code import Control.Monad import Control.Monad.Random psum :: (MonadRandom r) => Int

  • 0

The simple following code

import Control.Monad
import Control.Monad.Random

psum :: (MonadRandom r) => Int -> r Double -> r Double
psum n x = fmap sum $ replicateM n x

yields the error:

Could not deduce (Functor r) arising from a use of `fmap'
    from the context (MonadRandom r)

This is weird to me because of

class (Monad m) => MonadRandom m where ...

in Control.Monad.Random.Class source file, and since monads are functors, GHC should have deduced that r is a functor in my context. I also tried to import Control.Monad.Random.Class with no success.

Adding manually the Functor constraint on r works, but I find this quite ugly.

What am I missing here ?

  • 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-26T09:36:32+00:00Added an answer on May 26, 2026 at 9:36 am

    Theoretically monads are functors, but sadly Functor is not a superclass of Monad for no good reason.

    Instead of adding Functor r you can also use liftM instead of fmap.

    Edit: There really seems to be no good reason. The classes were introduced together in Haskell 1.3, and superclasses already existed and were used for MonadPlus and MonadZero.

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

Sidebar

Related Questions

I have the following simple Java code: package testj; import java.util.*; public class Query<T>
I have the following simple code: import urllib2 import sys sys.path.append('../BeautifulSoup/BeautifulSoup-3.1.0.1') from BeautifulSoup import
Hey Guys I have the following simple Code : WhereAmIViewController.h #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h>
I'm using the following code to import a simple excel spreadsheet into a dataset
I have the following simple code: import java.io.*; class IO { public static void
I have the following simple code: package test; import javax.swing.*; class KeyEventDemo { static
Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>
I have the following sample code which doesn't seem to want to run. import
i have the following simple code, but it doesn,t work <ul> <li id=one onmouseover=this.style.background-color='white';>
The following code has a simple binding which binds the Text of the TextBlock

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.