Hi,

Pls take a look at the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// System.Runtime.Seriaization.dll and System.Xml.dll are needed.

open System.IO
open System.Runtime.Serialization 
open System.Xml

let write(x : float32[]) =
    let ds = new DataContractSerializer(typeof @ float32[] @ ) // Please consider @ as > and <
    let ms = new MemoryStream()    
    ds.WriteObject(ms, x)
    ms.ToArray()

let read(x : byte[]) =
    let ds = new DataContractSerializer(typeof @ float32[] @)       // Please consider @ as > and <
    let ms = new MemoryStream(x);    
    ds.ReadObject(ms) :?> float32[]    

let x = [|1.0f; 2.0f; 3.0f|]
let xb = write(x)
let y = read(xb)
printfn "x = %A" x
printfn "y = %A" y

By the way, could you pls tell me how you do syntax high-lightening and manage not to disapper some symbols? Thanks.

Regards,

NNT

By on 1/22/2011 8:08 AM ()

Thank you very much, your code works!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#light
open System
open System.IO
open System.Runtime.Serialization
open System.Text
 
let write(x : float32[]) =
    let ds = new DataContractSerializer(typeof<float32[]>)
    let ms = new MemoryStream()
    ds.WriteObject(ms, x)
    ms.ToArray()
 
let read(x : byte[]) =
    let ds = new DataContractSerializer(typeof<float32[]>)
    let ms = new MemoryStream(x)
    ds.ReadObject(ms) :?> float32[]
 
let x = [|1.0f; 2.0f; 3.0f|]
let xb = write(x)
let y = read(xb)
printfn "x = %A" x
printfn "y = %A" x
printfn "Done"

My way to have format is simple: create the program.fs in VS2010, copy and paste the contents in MS-word, then copy and paste in this forum, even there are some garbage letters at the beginning, but the main body of program shows the color and format.

By on 1/22/2011 9:38 AM ()

Hi,

Thanks for the tip.

Regards,

NNT

By on 1/22/2011 6:44 PM ()
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