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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:39:56+00:00 2026-05-15T10:39:56+00:00

The lookup function in Data.Map and Data.IntMap currently return values wrapped in Maybe with

  • 0

The lookup function in Data.Map and Data.IntMap currently return values wrapped in Maybe with
the type signature

lookup  :: Ord  k => k -> Map  k a -> Maybe  a

It used to have the more general type of

lookup  :: (Monad  m, Ord  k) => k -> Map  k a -> m a

I realize the former likely reduces the need of extra type specification, but the latter would make it much more general and allow lookup to be used in list comprehensions. Is there any way to mimic this behavior with the newer version, or would I have to use an older version of the library?

  • 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-15T10:39:56+00:00Added an answer on May 15, 2026 at 10:39 am

    Don’s lift converts Maybe‘s elements to their general Monad counterparts, so perhaps it should be named convert or generalize or something;-)

    If you just want to use lookup mainly in list comprehensions and other monads that implement a fail, you could also make use of the mapping of pattern match failure to fail:

    Prelude> [ v | Just v <- return $ lookup "hi" [("ho","silver")] ]
    []
    Prelude> [ v | Just v <- return $ lookup "ho" [("ho","silver")] ]
    ["silver"]
    
    Prelude> do Just v <- return $ lookup "hi" [("ho","silver")] ; print v
    *** Exception: user error (Pattern match failure in do expression at <interactive>:1:3-8)
    Prelude> do Just v <- return $ lookup "ho" [("ho","silver")] ; print v
    "silver"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data structure which consists of pairs of values, the first of
I have a table containing hierarchical data. There are currently ~8 levels in this
I have the following function: appendMsg :: String -> (String, Integer) -> Map.Map (String,
function getUserData(name) { var userData = {}; twitter.get('http://api.twitter.com/1/users/lookup.json', {screen_name:name}, function(data) { userData = {
I have a lookup table called metadata_types in my database, which lists all the
I have several 'lookup' fields in my models where I don't want nulls, but
I have this function that is set a width to my inputs and ads
I have a Haskell Map, containing strings as keys and some lambda functions as
I have this javascript/ jquery to list available users. HTML: <input name=username type=text size=16
function lookupRemote(searchTerm) { var defaultReturnValue = 1010; var returnValue = defaultReturnValue; $.getJSON(remote, function(data) {

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.