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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:47:12+00:00 2026-05-24T23:47:12+00:00

I want to generate a vectorspace from a basis pair, which looks something like:

  • 0

I want to generate a vectorspace from a basis pair, which looks something like:

genFromPair (e1, e2) = [x*e1 + y*e2 | x <- [0..], y <- [0..]]

When I examine the output though, it sems like I’m getting [0, e2, 2*e2,...] (i.e. x never gets above 0). Which sort of makes sense when I think about how I would write the code to do this list comprehension.

I wrote some code to take expanding “shells” from the origin (first the ints with norm 0, then with norm 1, then norm 2…) but this is kind of annoying and specific to Z^2 – I’d have to rewrite it for Z^3 or Z[i] etc. Is there a cleaner way of doing this?

  • 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-24T23:47:13+00:00Added an answer on May 24, 2026 at 11:47 pm

    The data-ordlist package has some functions which are extremely useful for working with sorted infinite lits. One of these is mergeAllBy, which combines an infinite list of infinite lists using some comparison function.

    The idea is then to build an infinite list of lists such that y is fixed in each list, while x grows. As long as we can guarantee that each list is sorted, and that the heads of the lists are sorted, according to our ordering, we get a merged sorted list back.

    Here’s a quick example:

    import Data.List.Ordered
    import Data.Ord
    
    genFromPair (e1, e2) = mergeAllBy (comparing norm) [[x.*e1 + y.*e2 | x <- [0..]] | y <- [0..]]
    
    -- The rest just defines a simple vector type so we have something to play with
    data Vec a = Vec a a
        deriving (Eq, Show)
    
    instance Num a => Num (Vec a) where
        (Vec x1 y1) + (Vec x2 y2) = Vec (x1+x2) (y1+y2)
        -- ...
    
    s .* (Vec x y) = Vec (s*x) (s*y)     
    norm (Vec x y) = sqrt (x^2 + y^2)
    

    Trying this in GHCi we get the expected result:

    *Main> take 5 $ genFromPair (Vec 0 1, Vec 1 0)
    [Vec 0.0 0.0,Vec 0.0 1.0,Vec 1.0 0.0,Vec 1.0 1.0,Vec 0.0 2.0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate some formatted output of data retrieved from an MS-Access database
I want to generate heat map from a set of data which is latitude
I want to generate an abbreviation string like 'CMS' from the string 'Content Management
I want to generate a thread-like view In the table I have from,to,date and
I want to generate random colours which can be attractive in pie charts.I have
I want to generate facelets code from UIComponent, Eg: org.primefaces.component.commandbutton.CommandButton; CommandButton btn=new CommandButton(); btn.setValue(Click);
I want to generate incremental receipt numbers like this format 00000001. Every time new
I want to generate xml file from Struts action object. So that I have
I want generate a list of numbers from 0000 to 9999. I would then
I want to generate URL like.. It should include two IDs with employer and

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.