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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:40:59+00:00 2026-06-18T04:40:59+00:00

I am attempting to write a function using UArrays that are very general. I

  • 0

I am attempting to write a function using UArrays that are very general. I would like the type signature:

myFunction :: a -> b -> ((UArray Int a), (UArray Int b))

However, a and b are too general. I would like them to be one of the possible instances of IArray UArray a. Is there some deriving type that will allow me to specify this? For example, if Num were a valid instance I could do:

myFunction :: (Num a, Num b) => a -> b -> ((UArray Int a), (UArray Int b))

Does it make sense what I am trying to do?

Thanks in advance!

  • 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-18T04:41:00+00:00Added an answer on June 18, 2026 at 4:41 am

    We need to repeat constraints from array methods you are going to use, such as array etc. Since your indexes are fixed and we know they’re instance of Ix, we only need to add IArray constraints:

    myFunction :: (IArray UArray a, IArray UArray b)
               => a -> b -> ((UArray Int a), (UArray Int b))
    

    For this, you need the FlexibleContexts (see section 7.6.3.2. Relaxed rules for instance contexts) language extension.

    You could also think about generalizing your function to arbitrary arrays (not just UArrays

    myFunction1 :: (IArray arr a, IArray arr b)
                => a -> b -> ((arr Int a), (arr Int b))
    

    or perhaps even to arbitrary indexes:

    myFunction2 :: (IArray arr a, IArray arr b, Ix i)
                => a -> b -> ((arr i a), (arr i b))
    

    (For these 2 variants, you don’t need the extension.)

    Since probably you’re using UArrays for speed, I’d suggest adding INLINE pragma so that your function gets optimized for the particular data types at the place you use it. That can make a significant speed improvement.

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

Sidebar

Related Questions

I am attempting to write a JS function (using prototype in rails) that will
I'm attempting to write a function that generates a list of DateTimes using the
The task: I'm attempting to write a function with type signature minimum_recursive :: (a
I'm attempting to write a very basic script using javascript. What I want to
I'm attempting to write a search function for a database table that needs to
I'm attempting to write a function in assembly that sets a block of memory
I am attempting to write a function which tries to connect to Redis using
I'm attempting to write a function that recursively computes the resulting fibonacci number from
I am attempting to write a interpreter that will turn a string like: vector(random(0,
I am curretnly attempting to write a script in python that allows me to

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.