If you really need a mutable array you could use type ResizeArray<'T>.

Otherwise you coud use this:

let endArray = Set.toArray(Set.ofArray beginArray + Set.ofArray toAddArray)

or in more F# idiomatic style:

let endArray = set beginArray + set toAddArray |> Set.toArray

By on 10/30/2010 3:27 PM ()

Thanks for your code.
But the code is not what I want.
Since I have to test each element in toAddArray to see if such element is already in beginArray.
Your code simply skip the testing, even it gives the correct result, but I also need the testing, which is important in my programming.
But thanks anyway.

By on 10/31/2010 12:53 AM ()

Hi,

you don't need a mutable container to achieve the result that you want because the Array module in F# gives you the adequate functionality, i think this code solves your problem (sorry for the indentation):

let beginArray = [| "A"; "B"; "C" |]

let toAddArray = [| "B"; "D"; "E" |]

let endArray =

let arr =

[|

for x in toAddArray do

let exist = beginArray |> Array.tryFind (fun y -> y = x)

match exist with

| None -> yield x

| Some _ -> ()

|]

Array.concat [beginArray; arr]

Regards, Taha.

By on 10/31/2010 4:35 AM ()

Hi,
Thank you very much for your code.
I did find a way to use ResizeArray, and I think using ResizeArray is better.
I can understand F# prefers immutable data, but my programming needs from time to time mutable data.
Anyway, thanks for all who have offered help.

By on 10/31/2010 8:30 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper