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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:46:56+00:00 2026-05-31T23:46:56+00:00

My aim is to list all elements of the array a whose values are

  • 0

My aim is to list all elements of the array a whose values are greater than their index positions. I wrote a Haskell code like this.

[a|i<-[0..2],a<-[1..3],a!!i>i]

When tested on ghci prelude prompt, I get the following error message which I am unable to understand.

No instance for (Num [a]) arising from the literal 3 at <interactive>:1:20 Possible fix: add an instance declaration for (Num [a])

  • 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-31T23:46:57+00:00Added an answer on May 31, 2026 at 11:46 pm

    Given the expression a!!i, Haskell will infer that a is a list (i.e. a::[a]). Given the expression a<-[1..3], Haskell will infer that a will have type Num a => a (because you are drawing a from a list of Num a => a values). Trying to unify these types, Haskell concludes that a must actually be of type Num a => [a].

    The bottom line is that it doesn’t make sense to treat a as a list in one context and as an element from a list of numbers in another context.

    EDIT

    I’m thinking you could do what you want with something like this:

    f xs = map fst . filter (uncurry (>)) $ (xs `zip` [0..])
    

    The expression xs `zip` [0..] creates a list of pairs, where the first value in each pair is drawn from xs and the second value from [0..] (an infinite list starting from 0). This serves to associate an index to each value in xs. The expression uncurry (>) converts the < operator into a function that works on pairs. So the expression filter (uncurry (>)) filters a list of pairs to only those elements where the first value is greater than the second. Finally, map fst applies the fst function to each pair of values and returns the result as a list (the fst function returns the first value of a pair).

    EDIT 2

    Writing pointless code is fun, and so I give you:

    f = map snd . filter (uncurry (<)) . zip [0..]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using authorize.net AIM, the sample code they provide prints an ordered list of
I have a list in SharePoint 2010 with some columns. All are default types.
Drop-down lists, menus and combo boxes are all very common user interface elements. Users
I aim to have a list of lines where I use the word NB
My ultimate aim is to convert the below code in python to C#, but
Aim: to create an Infopath form that displays a list of companies in a
My aim is to select all the files named with MANI.txt which is present
Aim : To try a TCP connection to a list of server and print
AIM : Convert a resultset to XML and assign the result to a variable
Aim The aim is to a have a container DIV with a fixed height

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.