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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:10:19+00:00 2026-06-02T03:10:19+00:00

As an example, say I wish to implement a function which sums up a

  • 0

As an example, say I wish to implement a function which sums up a list of Nums. Halfway through coding it, I wish to debug it with Debug.Trace:

module T where
import Debug.Trace

dosum :: (Num a) => [a] -> a
dosum xs = dosum' 0 xs
    where
        dosum' n [] = n
        dosum' n (x:xs) = trace (show n) $ dosum' (n+x) xs

The problem is that this will not compile:

Could not deduce (Show a) arising from a use of dosum'
from the context (Num a)

I can add (Show a) to dosum and then remove it when I am finished debugging (in real life, I will want to have a type which is not necessarily in Show, but I will debug with integers). This can get cumbersome if there are a few functions involved and I keep adding removing Show a statements.

I want to have a function unsafeShow

unsafeShow :: a -> String

which works if a is Show a and is free to crash if it is not. Is this possible?

  • 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-02T03:10:22+00:00Added an answer on June 2, 2026 at 3:10 am

    The really really terrible answer is to use unsafeCoerce from the Unsafe.Coerce module. It is as it sounds – it is a general tool for bypassing the type system, and if you get it wrong, you won’t get a type error or an exception, you will get a segmentation fault.

    In this case, you can unsafeCoerce a value that you already know is an Integer to Integer so that the type system can recognise that it’s an integer too. Then you can show it as usual (make sure to give an explicit type signature, so show knows what it is showing – it can’t infer, since unsafeCoerce can return any type!)

    But if you accidentally call the code with unsafeCoerce on something other than an Integer, crashes, memory corruption, anything could happen – you’ve just completely thrown away your safety net.

    In general, the only “safe” uses of unsafeCoerce are between types that you already know are equal, but the typechecker doesn’t (or some other specialised use-cases, see the docs). Even then it will be heavily frowned upon by anyone reading your code unless your comments explain why it is the only option.

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

Sidebar

Related Questions

Lets say for example: $(.button).click(function() { $.post(commandrunner.php, { param1: 'value', param2: 'value2', param3: 'value3'
I wish to create a subtree from an hclust object. For example, let's say
Let's say I have an existing application written in Java which I wish to
I wish to request data from a web service endpoint( say http://www.example.com ) using
I wish to be able to run a VBA module which manipulates the table
i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
can you get the last or newly added element in std::set? for example say
For example lets say I have a JSON object that contains states and cities.
To use as an example: lets say that I have 2 EditText s and
How do you elegantly format a timespan to say example 1 hour 10 minutes

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.