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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:31:32+00:00 2026-05-28T04:31:32+00:00

I can construct an array with: array ((0,0),(10,10)) [((x,y),(x)) | x<-[0..10], y<-[0..10]] but I

  • 0

I can construct an array with:

array ((0,0),(10,10)) [((x,y),(x)) | x<-[0..10], y<-[0..10]]

but I can’t construct it with a function, not even something as simple as:

array ((0,0),(10,10)) [((x,y),f(x)) | x<-[0..10], y<-[0..10]]

What’s wrong with this?? Specifically, how can I convert the “x” to a Realfrac?

Edit – Nevermind, I was using function fromIntegral(num) num instead of function (fromIntegral num) num.

  • 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-28T04:31:33+00:00Added an answer on May 28, 2026 at 4:31 am

    The problem is that when you say (x*1.5), you’re forcing x to be a Fractional number — such as Float, Double or Rational — since (*) takes two values of the same type and returns a value of that same type, and of course 1.5 is a fractional number.

    The problem arises because you can’t make an array indexed by a floating-point number, only things like integers, tuples of integers and so on.1 What you probably mean to do is to keep x and y as integers, but convert them to a fractional type to calculate the value:

    array ((0,0),(10,10)) [((x,y), fromIntegral x * 1.5) | x<-[0..10], y<-[0..10]]
    

    Here, x and y are Integers, but fromIntegral x is a Double.2 What fromIntegral does is convert any Integral type (like Int, Int64, or Integer) into any Num (in this case, Double):

    fromIntegral :: (Integral a, Num b) => a -> b
    

    The end result is an array indexed by (Integer, Integer), with values of type Double, which is presumably what you wanted in the first place. 🙂

    1 Specifically, any instance of the Ix type-class will do; you can see the full list in the documentation.

    2 As for why Integer and Double are picked rather than any other Integral or Fractional, this is due to Haskell’s defaulting mechanism. Basically, if you have an ambiguous numeric type in your program, it’s first tried with Integer and if that doesn’t work (e.g. because the type has to be Fractional, which, as we’ve established, Integer isn’t), Double is tried instead. This is fairly arbitrary, but helps to eliminate ambiguity where it would otherwise crop up in a lot of silly places.

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

Sidebar

Related Questions

How can I construct my ajaxSend call, this seems like the place to put
I am not even sure how to ask. I do this all the time
I'm sure this has been asked before but I can't find it. The PHP
I have this question on the Wordpress stack exchange as well, but not having
i having problem understanding what is wrong with my inheritance. I just can not
I do not understand how I can send an array with options to my
Why does this return an array instead of an object and how can I
For some reason I'm not getting the expected output on this curl function, IF
Is there any way I can construct an new object from the given object
In python, I can construct my optparse instance such that it will automatically filter

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.