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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:27:21+00:00 2026-06-11T18:27:21+00:00

I am a F# newbie and I have a (probably simple) question. The purpose

  • 0

I am a F# newbie and I have a (probably simple) question.

The purpose of the code below is to copy the values from the sequence (bytestream) into the array myarray_, keeping the size of the array thesize, and having other elements set to zero.

I can see the values being copied in the for loop. But after leaving the constructor, the debugger shows that myarray_ of the newly constructed object contains all zeros!

I am using VS2012. Thanks.

EDIT: The size of the recipient array is always bigger than the size of the incoming sequence.

EDIT: The object of this SomeClass is actually instantiated as a member of an outer class. Here it is, along with more context in ‘SomeClass’.
When the main program calls OuterClass.Func, the “cp” objects gets created, and the array gets properly populated. When the code leaves the ctor the array either contains all zeros, or it has size zero (see comments below).

** SOLVED? ** : I changed “cp” from “member” to “let mutable”… it seems to work now. Not sure to understand why.

type SomeClass(thesize, bytestream : seq<byte>) = class
    let mutable myarray_ = Array.create<byte> thesize 0uy

    do
        let mutable idx = 0
        for v in bytestream do
            myarray_.[idx] <- v
            idx <- idx + 1

    member x.Func(index) = // consumes myarray_.[index] and neighbor values


type OuterClass(thesize, bytestream) = class
    member x.cp : SomeClass = new SomeClass(thesize, bytestream)
    member x.Func(index) =
        x.cp.Func(index)
  • 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-11T18:27:22+00:00Added an answer on June 11, 2026 at 6:27 pm

    You declare myarray_ as a mutable value, so it’s possible to assign it to a newly created array somewhere in your code. You should not use mutable keyword because you want to update array elements, not change the array to a new one.

    Assume that thesize is bigger than length of bytestream:

    type SomeClass(thesize, bytestream : seq<byte>) =
        let myarray_ = [| yield! bytestream
                          for i in (Seq.length bytestream)..(thesize-1) -> 0uy |]
        ....
    

    EDIT:

    With

    member x.cp : SomeClass = new SomeClass(thesize, bytestream)
    

    you essentially instantiate a new instance of SomeClass each time the property is used. Therefore, you will not see the effects of x.Func on the old SomeClass. What you probably want is:

    type OuterClass(thesize, bytestream) =
        let cp = new SomeClass(thesize, bytestream)
        member x.cp = cp
    

    where the instance is only constructed once in the default constructor.

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

Sidebar

Related Questions

I'm a newbie with WPF and c# and have a (probably very simple) problem.
Newbie here with a frustrating, but probably simple question. I am trying to write
Probably a newbie question but I'll ask anyway. Have a multipage form that I
Probably a newbie question, but everyone seems to use e.printStackTrace() , but I have
Probably a very newbie question but, Ive been reading around and have found some
Probably this is a newbie question :) But I have some Flash games built
This is a simple newbie question. I could probably figure this out using some
This is probably a newbie question. I have a table USER which contains info
While trying out jQuery, I have a question that is probably a newbie mistake,
I'm a bit of a NuGet newbie and have come from the Maven world.

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.