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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:08:26+00:00 2026-05-31T20:08:26+00:00

This portion of code checks if a number given (First element in a list)

  • 0

This portion of code checks if a number given (First element in a list) is zero
(yes i tried == 0 but got other errors)
It then return all elements of another list except the first one.
If not, it returns another list.
The function is of type [a] and ‘newpack’ needs to be a variable as it is used later.

                              if ((position!!1) < 1)
                                then 
                                    let newpack =   drop ((length pack)-1) pack
                                else
                                    let newpack = (take ((position!!1)-1) pack) ++ (drop ((position!!1)+1) pack)

error is 46:73: parse error on input `else’

Do have any idea why this is not working? Is it that’let’s needs an ‘in’ with them?

Thanks for your help,

J

  • 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-31T20:08:27+00:00Added an answer on May 31, 2026 at 8:08 pm

    Yes, the in part is not optional. You can write this as:

    let newpack = if (position !! 1) < 1
                    then drop ((length pack)-1) pack
                    else (take ((position!!1)-1) pack) ++ (drop ((position!!1)+1) pack)
    in ...rest of code...
    

    If you’re in a do block, then you can omit in onwards, but either way, you can’t put the conditional outside the binding.

    (If you’re hoping to modify newpack as if it was a mutable variable, that’s just not possible; all let does is give a name to a value, you can’t actually modify anything. But how to structure your code without this would be beyond the scope of this question; if you need help with that, you should ask another.)

    Some stylistic notes:

    • Explicit list indexing is generally considered a bad idea; depending on what it’s used for, you might want to consider making position a tuple or some other data structure.

    • Similarly, length is probably a bad idea too (it has to traverse the entire list just to give a result).

    • You have a lot of redundant parentheses: drop ((length pack)-1) can be simply drop (length pack - 1).

    A nicer way to write this (from a purely aesthetic point of view — i.e. ignoring the list indexing and use of length) would be (using guards):

    let firstPos = position !! 1
        newPack
          | firstPos == 0 = drop (length pack - 1) pack
          | otherwise     = take (firstPos - 1) pack ++ drop (firstPos + 1) pack
    in ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone explain to me what this portion of code means? repeat scroll 0
following up from yesterday... This portion of the code does work. $(document).ready(function(){ $('#listMenu a').click(function
Let's say we have a code portion like this: IProduct product = ProductCreator.CreateProduct(); //Factory
I'm looking through some code for learning purposes. I'm working through this portion of
i don't understand how this happen. This is portion of my code.. int isGoal(Node
I got a portion of javascript code embedded in HTML (generated on the server
This portion of code parses XML for output to the screen on a webpage.
this portion of code is outputing 01/01/1970. is my code incorrect? i have only
First, this could look like duplicate for How to prevent your JavaScript code from
I've got this code, which I don't understand why it doesn't compile: typedef struct

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.