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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:50:27+00:00 2026-05-26T12:50:27+00:00

I am trying to scale a sequence by the first element of the sequence,

  • 0

I am trying to scale a sequence by the first element of the sequence, so the first element will always be one, and then subsequent elements are a ratio of the first element to the nth element of the original sequence.

Here is my code,

       open System
       open System.Collections

           let squish1 (x:Double seq) =
                let r =  (Seq.head x:Double)
                Seq.fold (fun (xi:Double) (r:Double) -> xi/r);;

And I test on this little vector:-

                squish1 [|5.0; 1.0; 1.0; 1.0; 1.0; 1.0|];;

I have typed everything because I get this error message

normaliseSequence.fsx(9,1): error FS0030: Value restriction. The value ‘it’ has been >inferred to have generic type
val it : (Double -> ‘_a -> Double) when ‘_a :> seq
Either make the arguments to ‘it’ explicit or, if you do not intend for it to be generic, >add a type annotation.

But clearly I am misunderstanding because I get the error message even with everything typed. What am I missing?

Any and all advice gratefully received. Thanks

  • 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-26T12:50:28+00:00Added an answer on May 26, 2026 at 12:50 pm

    fold expects two more parameters, the seed value and the sequence. This works:

    let squish1 (x:Double seq) =
        let r =  (Seq.head x:Double)
        Seq.fold (fun (xi:Double) (r:Double) -> xi/r) 0.0 x
    

    However, I’m guessing you probably want map instead of fold:

    let squish1 (x:Double seq) =
        let r =  (Seq.head x:Double)
        Seq.map (fun (xi:Double) -> xi/r) x
    

    Incidentally, I would probably write it this way:

    let inline squish1 (x:seq<_>) =
      let r = Seq.head x
      Seq.map (fun n -> n / r) x
    

    Now it works for all types that support division.

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

Sidebar

Related Questions

I am trying to scale images to fit within their parent element width, and
I'm trying to rotate and then scale an image using android.graphics.Matrix. The code is
I'm trying to scale an image down, change the image, then scale it back
I have a set of path elements that I'm trying to scale with animation.
I'm trying to get every widget to scale with change in window size. I
I am trying to parallelise a code using scala actors. That is my first
I'm trying to replace a bunch of Linux shell scripts with Scala scripts. One
I'm trying to learn Scala and tried to write a sequence comprehension that extracts
Here is my problem: I have a sequence S of (nonempty but possibly not
Should be an easy one. I'm working on Scala trying to handle long sequences

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.