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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:58:28+00:00 2026-06-08T02:58:28+00:00

I’d like to supply my own instance for the list monad. Unfortunately, the following

  • 0

I’d like to supply my own instance for the list monad. Unfortunately, the following causes a duplicate instance declaration error when compiling.

myReturn :: a -> [a]
myBind :: [a] -> (a -> [b]) -> [b]
instance Monad [] where
    return = myReturn
    (>>=) = myBind

From the documentation, it seems like it’s not possible to hide instance declarations when importing, and since the list monad instance is already declared in the prelude, I guess I can’t get rid of the import itself either.

I figured that maybe I could at least rebind (>>=) and return so that I would be able to use do blocks using my own implementation since do blocks are supposedly just syntactic sugar for applications of (>>=) and (>>).

let
    return = myReturn
    (>>=) = myBind
in
    do
        item1 <- list1
        item2 <- list2
        return (item1, item2)

Unfortunately, it seems like do blocks get their (>>=) from somewhere else, because it’s still using the (>>=) of the default list monad instance.

Is there any way to make my implementations of (>>=) and return an instance of list monad, or at least a way to use them with do blocks?

  • 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-08T02:58:29+00:00Added an answer on June 8, 2026 at 2:58 am

    You cannot define another Monad instance for lists, in some circumstances you can define a newtype to work around that, but you’d have to manually lift all list functions to the newtype to use them.

    To just use your own (>>=) and return in do-blocks, you can use a language extension with GHC:

    {-# LANGUAGE NoImplicitPrelude #-}
    module ListMon where
    
    import Prelude hiding ((>>=), return)
    
    (>>=) :: [a] -> (a -> [b]) -> [b]
    xs >>= foo = case xs of
                   [] -> [undefined]
                   [x] -> foo x ++ foo x
                   ys -> take 10 $ concatMap foo $ take 5 ys
    
    return :: a -> [a]
    return x = [x,x,x]
    
    someList :: [Int]
    someList = do
        k <- [1 .. 4]
        h <- [2 .. 3]
        return (k + 12*h)
    

    resulting in

    $ ghci ListMon
    {- snip loading messages -}
    [1 of 1] Compiling ListMon          ( ListMon.hs, interpreted )
    Ok, modules loaded:
    *ListMon> someList 
    [25,25,25,37,37,37,26,26,26,38,38,38,27,27,27,39,39,39,28,28,28,40,40,40]
    

    With NoImplicitPrelude, desugaring of do-notation uses whatever (>>=) and return are in scope.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to count the length of a string with PHP. The string
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.