OK, sorted out the issue, more to do with the correct application of brackets to nested function calls rather than anything else.
If any-one wants the code here it is (NOTE DECR doesn't appear in the supplied code - it's something I added as an experiment ) :-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Microsoft Corporation 2005-2006.
// This sample code is provided "as is" without warranty of any kind. 
// We disclaim all warranties, either express or implied, including the 
// warranties of merchantability and fitness for a particular purpose. 
open StructuredFormat
open StructuredFormat.LayoutOps

let get_layout (env: #IEnvironment) (e: #IFormattable) = e.GetLayout(env)

type expr = 
	| Val of string 
	| Int of int
	| Float of float
	| Decr of expr
	with 
		interface StructuredFormat.IFormattable with
			member x.GetLayout(env) =
				match x with
				| Val s -> objL (box s)
				| Int i -> objL (box i)
				| Float f -> objL (box f)
				| Decr t1 -> wordL "decr" $$ leftL "(" $$ get_layout env t1 $$ rightL ")"
		end
end

type stmt = 
	| Assign of string * expr
	| While of expr * stmt
	| Seq of stmt list
	| IfThen of expr * stmt
	| IfThenElse of expr * stmt * stmt
	| Print of expr
	with 
		interface StructuredFormat.IFormattable with
			member x.GetLayout(env) =
				match x with
					| Assign (t1, t2) ->
				wordL t1 ++ wordL "=" ++ get_layout env t2
					| While (t1, t2) ->
				wordL "while" ++ get_layout env t1 @@-- get_layout env t2
					| Seq (t1 ) -> wordL "begin" @@ aboveListL ( List.map ( fun n -> get_layout env n $$ wordL ";" ) t1 ) @@ wordL "end"
					| IfThen( t1, t2) ->
				wordL "if" ++ get_layout env t1 ++ wordL "then" @@-- get_layout env t2
					| IfThenElse( t1, t2, t3) ->
				wordL "if" ++ get_layout env t1 ++ wordL "then" @@-- get_layout env t2 ++ wordL "else" @@-- get_layout env t3 
					| Print( t1 ) ->
					wordL "print" ++ get_layout env t1 
		end
end

type prog = Prog of stmt list
	with 
		interface StructuredFormat.IFormattable with
			member x.GetLayout(env) =
				match x with
				| Prog (t1 ) -> aboveListL ( List.map ( fun n -> get_layout env n $$ wordL ";" ) t1 )
		end
end


Enjoy..................................
Mark

By on 3/20/2008 8:30 AM ()

Microsoft.FSharp.Text.StructuredFormat.LayoutOps.Layout is marked as deprecated:

warning FS0044: This construct is deprecated. This property will be removed from the F# library and should no longer be used. Object formatting can be implemented by using the default rules of the printfn '%A' format, overriding the 'ToString' method on a type, registering a printer in F# Interactive or by creating a .NET debugger visualizer for your type

What should be done, then, when printing out expression trees (like the example above)? Are there some alternative pretty printing utilities available, or in the pipeline?

By on 3/19/2009 10:34 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