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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:24:59+00:00 2026-05-13T19:24:59+00:00

This works: data Wrapped a = Wrapped a alpha :: IO s -> IO

  • 0

This works:

data Wrapped a = Wrapped a

alpha :: IO s -> IO ()
alpha x = do
    rv <- wrapit x
    return ()
    where       
        wrapit :: IO s -> IO (Wrapped s)
        wrapit x' = do 
            a <- x'
            return (Wrapped a)

This doesn’t:

data Wrapped a = Wrapped a

alpha :: IO s -> IO ()
alpha x = do
    rv <- wrapit
    return ()
    where       
        wrapit :: IO (Wrapped s)
        wrapit = do 
            a <- x
            return (Wrapped a)

Why?

  • 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-13T19:24:59+00:00Added an answer on May 13, 2026 at 7:24 pm

    This is due to the way in which type variables are scoped and quantified in standard Haskell. You can make the second version work like so:

    {-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
    
    module RigidProblem where
    
    data Wrapped a = Wrapped a
    
    alpha :: forall s. IO s -> IO ()                                                
    alpha x = do
        rv <- wrapit
        return ()
        where       
            wrapit :: IO (Wrapped s)
            wrapit = do 
                a <- x
                return (Wrapped a)
    

    There are two changes: the RankNTypes and ScopedTypeVariables language extensions are enabled and the explicit forall s is added in the type signature of alpha. The first of the two extensions is what allows us to introduce the explicit forall s thus bringing the s into scope inside the body of alpha, whereas the second makes it so that the signature on wrapit is not taken by the type inference engine to contain an implicit forall s — instead, the s in that signature is taken to name a type variable which should be in scope and is identified with it.

    The current default situation in Haskell, if I understand correctly, is that all rigid type variables (meaning type variables occurring in type signatures explicitly provided by the programmer) are implicitly quantified and not lexically scoped, so that there is no way to refer to a rigid type variable from an outer scope in an explicit signature provided in an inner scope… (Oh bother, I’m sure someone could phrase it better than this.) Anyway, from the type checker’s point of view, the s in alpha‘s signature and the one in wrapit‘s signature are totally unrelated and cannot be unified — thus the error.

    See this page from the GHC docs and this page from Haskell Prime wiki for more information.

    Update: I just realised that I never explained why the first version works. For the sake of completeness: note that with the first version, you could use t in place of s in wrapit‘s signature and nothing would change. You could even take wrapit out of the where block and make it a separate top level function. The key point is that it is a polymorphic function, so that the type of wrapit x is determined by the type of x. No relation of the type variable used in the first version wrapit‘s signature to that used in alpha‘s signature would be of any use here. With the second version this is of course different and you have to resort to the above mentioned trickery to make wrapit‘s s be the same thing as alpha‘s s.

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

Sidebar

Ask A Question

Stats

  • Questions 306k
  • Answers 306k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer According Maxim in the comments below this answer is now… May 13, 2026 at 9:23 pm
  • Editorial Team
    Editorial Team added an answer You can take snapshots a few ways, this way just… May 13, 2026 at 9:23 pm
  • Editorial Team
    Editorial Team added an answer You can easily print the output results of a ref_cursor… May 13, 2026 at 9:23 pm

Related Questions

I'm doing IPC on Linux using boost::interprocess::shared_memory_object as per the reference (anonymous mutex example).
I have a situation where I've wrapped a Native C++ DLL with C++/CLI for
I've got a loop in my code that uses std::basic_string<HANDLE> , and then waits
I want to reload a page so that it does not cause the effects
I have a Java JDBC application that uses multiple threads to retrieve information from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.