You might want look at F#'s printf functions. The place holders in this are typed so you can avoid the need for boxing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#light
open System.IO
let data = Map.FromList [1,"one";2,"two";3,"three";]

let printMap m =
    let textBuffer =
        Map.fold 
            (fun key value acc -> 
                Printf.fprintfn acc "%i -> %s" key value
                acc) 
            m 
            (new StringWriter() :> TextWriter) 
    textBuffer.ToString()
 
printMap data
By on 12/13/2007 4:57 AM ()

Hi Robert,

I am not familiar with the Printf functions. Are they described in your book? I ordered the book but my bookstore (in Japan) asked 3 weeks to deliver it, so I am waiting.

Thanks.

By on 12/13/2007 9:25 PM ()

Sorry to hear about your delivery problems - I hope it turns up soon.

The printf functions are covered in the book with details of the meaning of all the place holders and a few examples. The functions are also covered here:
[link:research.microsoft.com]

Thanks,
Robert

By on 12/14/2007 1:00 AM ()

Hi solidstate,

It's impossible to be sure without a compiling example, or at least the type of m._vars value, but it could be that you need to box key and value.

1
2
3
4
5
6
member m.formatVarTable () =
    let s1 = new System.Text.StringBuilder () in
    m._vars.Iterate
            (fun key value ->
                s1.AppendFormat ("{0} -> {1}\n", box key, box value));
    s1.ToString ();

box'ing will return a heap allocated obj which should have the right type and interop with the dotnet function call.

Regards,

Daniel

By on 12/13/2007 2:20 AM ()

Hi Daniel,

Thanks for the help. The boxing worked just fine.

Regards.

By on 12/13/2007 9:22 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