Guest User

Untitled

a guest
Jan 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. type SomeClass(thesize, bytestream : seq<byte>) = class
  2. let mutable myarray_ = Array.create<byte> thesize 0uy
  3.  
  4. do
  5. let mutable idx = 0
  6. for v in bytestream do
  7. myarray_.[idx] <- v
  8. idx <- idx + 1
  9.  
  10. member x.Func(index) = // consumes myarray_.[index] and neighbor values
  11.  
  12.  
  13. type OuterClass(thesize, bytestream) = class
  14. member x.cp : SomeClass = new SomeClass(thesize, bytestream)
  15. member x.Func(index) =
  16. x.cp.Func(index)
  17.  
  18. type SomeClass(thesize, bytestream : seq<byte>) =
  19. let myarray_ = [| yield! bytestream
  20. for i in (Seq.length bytestream)..(thesize-1) -> 0uy |]
  21. ....
  22.  
  23. member x.cp : SomeClass = new SomeClass(thesize, bytestream)
  24.  
  25. type OuterClass(thesize, bytestream) =
  26. let cp = new SomeClass(thesize, bytestream)
  27. member x.cp = cp
  28.  
  29. type SomeClass(size, bytes : seq<byte>) =
  30. let buf = Array.zeroCreate size
  31. do
  32. // Here code assumes that size is always greater than number of items in bytes, is it always correct ?
  33. Seq.iteri(fun i b -> buf.[i] <- b) bytes
  34. member this.Buffer = buf
  35.  
  36. let v = SomeClass(5, (List.init 3 byte))
  37. printfn "%A" v.Buffer // printf [|0uy; 1uy; 2uy; 0uy; 0uy|]
Add Comment
Please, Sign In to add comment