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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:17:01+00:00 2026-05-23T08:17:01+00:00

I’m working on a complicated function in yesod. It has a lot of functions

  • 0

I’m working on a complicated function in yesod. It has a lot of functions in the where portion that are untyped, but typecheck properly. I decided to try and add a few type signatures so that I could figure out what was going on one piece at a time, but adding the type signatures caused type errors.

So I pared down the function to a simple case to post here, which still gives a similar error that I don’t understand.

helper :: [(String, a)] -> [(Int, a)]
helper xs = blah
  where
    blah :: [(Int, a)]
    blah = zip [1..10] (map snd xs)

If I remove the type signature from blah, it compiles just fine, but if I add that type signature it gives me the error:

Couldn't match type `a' with `a1'
  `a' is a rigid type variable bound by
      the type signature for helper :: [(String, a)] -> [(Int, a)]
      at Blah.hs:4:1
  `a1' is a rigid type variable bound by
       the type signature for blah :: [(Int, a1)] at Blah.hs:7:5
Expected type: [(String, a1)]
  Actual type: [(String, a)]
In the second argument of `map', namely `xs'
In the second argument of `zip', namely `(map snd xs)'
  1. I also have no idea why the “a” in helper is interpretted as a different “a” than helper when typechecking goes forth.
  2. Why it even cares if the a’s are different in the first place
  3. I have no idea how to figure out what type blah actually is, because I can’t move it to the toplevel while still using its argument.

Edit:

Okay, I have one more edit before I mark this answered. In the code I’m using there are some constraints (Eq a, Monad monad) => etc, etc, etc. and so the solution I have doesn’t quite work. So I’m modifying my sample code to be more close to the real code:

helper :: (Eq a, Num b) => b -> [(String, a)] -> (b, [(Int, a)])
helper b xs = (b+b, blah)
  where
    blah :: [(Int, a)]
    blah = filter (\y -> fst y == 11) $ zip [1..10] (map snd xs)

If I put

helper :: forall a. (Eq a, Num b) => b -> [(String, a)] -> (b, [(Int, a)])

this doesn’t work because (I assume because b is not in scope, but I can’t figure out the syntax to get forall b into this type. (forall a, forall b doesn’t work, forall a,b doesn’t work).

  • 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-23T08:17:02+00:00Added an answer on May 23, 2026 at 8:17 am

    The a in the type of blah is not the same as the a in the type of helper, unless you use the ScopedTypeVariables extension. So your type signatures are saying that they are independent, but they are clearly not.
    Your code is equivalent to this:

    helper :: forall a. [(String, a)] -> [(Int, a)]
    helper xs = blah
      where
        blah :: forall b. [(Int, b)]
        blah = zip [1..10] (map snd xs)
    

    Here you are saying that for any given a, we can choose any b, but that’s not true. Since xs has type [(String, a)], map snd xs has type [a]. So a and b must be the same type, i.e. a ~ b. Thus the compiler complains that blah isn’t as polymorphic as you said it was in the type signature.

    You have three options:

    • Remove the type signature. The compiler will infer the correct type for blah.

    • Enable ScopedTypeVariables. The compiler will then realise that you wanted the a in the type of blah to be the same as the a in the signature of helper. In this case, you need to add an explicit forall a. to the type signature of helper:

      {-# LANGUAGE ScopedTypeVariables #-}
      helper :: forall a. [(String, a)] -> [(Int, a)]
      helper xs = blah
        where
          blah :: [(Int, a)]
          blah = zip [1..10] (map snd xs)
      
    • Make the type of blah independent:

      helper :: [(String, a)] -> [(Int, a)]
      helper xs = blah xs
        where
          blah :: [(String, b)] -> [(Int, b)] -- Or 'a'. Doesn't matter.
          blah ys = zip [1..10] (map snd ys)
      

      Now blah will work on any b. The fact that you only use it with b ~ a is perfectly fine.

    Answer to edit:

    Use a space between the type variables in the forall, e.g.

    helper :: forall a b. (Eq a, Num b) => ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.