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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:57:36+00:00 2026-05-27T06:57:36+00:00

I have a data type which contains an IORef as an important element. This

  • 0

I have a data type which contains an IORef as an important element. This means there is not a clean way to make it a member of the show type class. This is not too bad as I have a print function in the IO monad for this type. But it is annoying in GHCi in that every time I return one of these thing as a result I get an error stating that it cannot be shown.

Is there a way to get GHCi, which operates in the IO monad anyway, to use an IO action to show a result? If not, would there be any negative consequences to writing show a = unsafePerformIO $ print a?

  • 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-27T06:57:36+00:00Added an answer on May 27, 2026 at 6:57 am

    Have you considered adding to your .ghci file something like:

    instance (Show a) => Show (IORef a) where
        show a = show (unsafePerformIO (readIORef a))
    

    It isn’t safe at all, but if this is just for your personal use perhaps that is OK.

    For more general use the previously given answers look good to me. That is, either define a static “I can’t show this” message:

    instance Show (IORef a) where
        show _ = "<ioref>"
    

    This would give something like:

    > runFunc
    MyStruct <ioref> 4 "string val"
    

    Or use a custom function. I suggest making a class and lifting all the Show instances:

    class ShowIO a where
        showIO :: a -> IO String
    
    instance Show a => ShowIO a where
        showIO = return . show
    instance ShowIO a => ShowIO (IORef a) where
        showIO a = readIORef a >>= showIO
    

    Giving the output (untested, this is just hand-written):

    > myFunc >>= showIO
    MyStruct "My String in an IORef" 4 "string val"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text data file which contains text like this: [category.type.group.subgroup] - 2934:10,4388:20,3949:30
I have a universal data type, which is passed by value, but does not
I have a table, which contains many columns of float data type with 15
i have table called type which contains data family,individual i want in some pages
I have a database column which contains varchar data type. I would like to
I have one database which contains username, password and IsActive (data type is bit)
I have a field in a table with varchar data type which contains the
I have a column which is of datetime data type. It contains few entries.
I have a table which contains two type of data, either for Company or
Since MySQL doesn't seem to have any 'boolean' data type, which data type do

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.