I would stick with the array. What is the list buying you? Nothing (apart from bad perf) that I can see. The array is a local variable in the getRecord function. A little temporary local mutable state never hurt anyone. :)

By on 4/11/2009 1:12 PM ()

I guess I just associate consuming with functional and offsets/pointers with imperative...

An alternative would be to create a BinFile type, which could be consumed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
type BinFile(fileName : string) =
    let bytes = File.ReadAllBytes fileName
    let mutable offset = 0
    
    member f.getInt16 =
        let ret = (int bytes.[offset] <<< 8) + int bytes.[offset+1]
        offset <- offset + 2
        ret
 
let getRecord fileName =
    let file = BinFile(fileName)

    let recType = file.getInt16
    let recLen  = file.getInt16
    // ...

Anyway, it turned out to be cleaner to generate a list of (recType, recLen, offsetInFileBytes) in this particular case.

By on 4/12/2009 10:16 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