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

The Archive Base Latest Questions

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

Here is my code: sumOfSquare :: Int -> Int -> Int sumOfSquare a b

  • 0

Here is my code:

sumOfSquare :: Int -> Int -> Int
sumOfSquare a b = a * a + b * b

hipotenuse :: Int -> Int -> Int
hipotenuse a b = truncate(sqrt(x))
           where x = fromIntegral(sumOfSquare a b)

squareCheck :: Int -> Bool
squareCheck n = truncate(sqrt(x)) * truncate(sqrt(x)) == n
         where x = fromIntegral n

isItSquare :: Int -> Int -> Bool
isItSquare a b = squareCheck (sumOfSquare a b)

data SidesType = Sides Int Int Int deriving (Show)

calc :: Int -> [SidesType]
calc a = [(Sides x y (hipotenuse x y)) | x <- [1..a], y <-[1..a], (isItSquare x y)]

test :: Int -> SidesType
test a = (Sides 1 2 3)

I need to display result of calc. It doesn’t work:

*Main> calc
<interactive>:1:0:
    No instance for (Show (Int -> [SidesType]))
      arising from a use of `print' at <interactive>:1:0-3
    Possible fix:
      add an instance declaration for (Show (Int -> [SidesType]))
    In a stmt of an interactive GHCi command: print it

Call of test works correcly:

*Main> test 1
Sides 1 2 3

As I understanded the reason is the calc function return the list of SidesType and Haskell can display a SidesType, but cannot display the list of SidesType.

Do I need to change my SidesType description? Or do I need to fix error somehow else?

And another one question – can I display the result of calc function without defining new datatype:

calc :: Int -> (Int, Int, Int)
calc a = [x y (hipotenuse x y) | x <- [1..a], y <-[1..a], (isItSquare x y)]

?

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

    Displaying the result of calc is done just as you did with the result of test:

    *Main> calc 4
    [Sides 3 4 5,Sides 4 3 5]
    

    You tried to display the value of calc, which you can’t do; there’s no representation of a function which can be printed (which should make sense—show is, at least by default, supposed to display something which can be read back in, and you can’t do that with functions). If Haskell can display something, then it can display a list of something; there’s a declaration somewhere of

    instance Show a => Show [a] where
      ...
    

    (And there are similar instances for Read, Eq, and Ord: lists of readable things are themselves readable, lists of things which can be compared for equality can themselves be compared for equality, and lists of things which can be ordered can themselves be ordered.)

    And yes, you can use a tuple instead of defining SidesType:

    calc :: Int -> [(Int, Int, Int)]
    calc a = [(x,y,hipotenuse x y) | x <- [1..a], y <- [1..a], isItSquare x y]
    

    What you wrote—x y (hipotenuse x y)—tries to call the function x with the two arguments y and hipotenuse x y. Of course, x isn’t a function, so this can’t work. You need the commas and parentheses instead.


    Also, since you seem to be new to Haskell, here are a few small style points: people typically write truncate $ sqrt x or truncate (sqrt x) instead of truncate(sqrt(x)), and the parentheses around isItSquare x y and Sides x y (hypotenuse x y) (which one could also write Sides x y $ hypotenuse x y) in the list comprehension are unnecessary. I’d also probably write data Sides = Sides Int Int Int deriving (Eq,Show,Read) instead of data SidesType = Sides ..., but I’d really probably use (Int,Int,Int) instead, as you indicate you want to. And I’d probably give the functions a more generic type by replacing Int with an instance of Integral; for instance, calc :: Integral i => i -> [(i,i,i)]. But this is more of a matter of taste.

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

Sidebar

Related Questions

Here is code: public interface IAccessPoint { int BackHaulMaximum { get; set; } bool
const static int foo = 42; I saw this in some code here on
Edit: The code here still has some bugs in it, and it could do
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
We have some old C code here that's built with nmake. Is there an
I am using pseudo-code here, but this is in JavaScript. With the most efficient
I have a piece of code here that i really could use some help
I've got this code here: SqlCommand CodeStatus = new SqlCommand(SQL, DB); DB.Open(); Reader =
I am compiling a legacy C code here and there is a lot of

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.