-
Notifications
You must be signed in to change notification settings - Fork 5
/
FsPad.fsx
2895 lines (2386 loc) · 101 KB
/
FsPad.fsx
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module FsHtml
type Html =
| Elem of string * Html list
| Attr of string * string
| Text of string
with
static member toString elem =
let rec toString indent elem =
let spaces = String.replicate indent " "
match elem with
| Attr(name,value) -> name+"=\""+value+"\""
| Elem(tag, [Text s]) ->
spaces+"<"+tag+">"+s+"</"+tag+">\r\n"
| Elem(tag, content) ->
let isAttr = function Attr _ -> true | _ -> false
let attrs, elems = content |> List.partition isAttr
let attrs =
if attrs = [] then ""
else " " + String.concat " " [for attr in attrs -> toString 0 attr]
match elems with
| [] -> spaces+"<"+tag+attrs+"/>\r\n"
| _ ->
spaces+"<"+tag+attrs+">\r\n"+
String.concat "" [for e in elems -> toString (indent+1) e] +
spaces+"</"+tag+">\r\n"
| Text(text) ->
spaces + text + "\r\n"
toString 0 elem
override this.ToString() = Html.toString this
let elem tag content = Elem(tag,content)
let html = elem "html"
let head = elem "head"
let title = elem "title"
let style = elem "style"
let body = elem "body"
let div = elem "div"
let br = elem "br"
let section = elem "section"
let span = elem "span"
let table = elem "table"
let thead = elem "thead"
let tbody = elem "tbody"
let tfoot = elem "tfoot"
let img = elem "img"
let map = elem "map"
let area = elem "area"
let p = elem "p"
let a = elem "a"
let tr = elem "tr"
let td = elem "td"
let th = elem "th"
let ul = elem "ul"
let li = elem "li"
let h1 = elem "h1"
let h2 = elem "h2"
let h3 = elem "h3"
let h4 = elem "h4"
let strong = elem "strong"
let (~%) s = [Text(s.ToString())]
let (%=) name value = Attr(name,value)
namespace FsPad
open System
module Representation =
/// A primitive value that has a JavaScript representation.
type Primitive = obj
type ChunkId = System.Guid
/// A named field with a value (i.e. a field or a column in the UI)
type FieldValue<'label> = { name: string; value: LabelledNode<'label> }
/// Tree representing the value with extra information.
and LabelledNode<'label> =
/// Primitive value.
| Scalar of 'label * Primitive
/// A sequence of values
| Sequence of 'label * LabelledNode<'label> list
/// A complex value
| Mapping of 'label * FieldValue<'label> list
/// A value to be calculated lazily - we will maintain a collection
/// of chunks keyed by ids to be evaluated on demand, though we'd need
/// to have a server around for that.
| Chunk of 'label * ChunkId
member this.Label =
match this with
| Scalar (lbl, _)
| Sequence (lbl, _)
| Mapping (lbl, _)
| Chunk (lbl, _) -> lbl
/// Type of the named field.
type FieldType<'label> = { name: string; schema: 'label }
/// Discriminates different variants of types in F# that we might want to
/// distinguish in the UI.
type Variant =
| Primitive
| Poco
| Record
| Union
| Collection
| Tuple
| Function
/// This can be used to match a template for the display.
/// It should be expressive enough for us to be able to have different templates for:
/// - discriminated unions in general
/// - options specifically
/// - int options (if it somehow made sense to have something very specific for them)
type TypePattern =
{
typeName: string
variant: Variant
genericTypeArgs: TypePattern list
}
member pattern.DisplayName =
match pattern.genericTypeArgs with
| [] -> sprintf "%s" pattern.typeName
| other ->
if pattern.variant = Variant.Tuple then
String.Join(" * ", List.map (fun (x: TypePattern) -> x.DisplayName) other)
else
let args =
String.Join(",", List.map (fun (x: TypePattern) -> x.DisplayName) other)
sprintf "%s<%s>" pattern.typeName args
/// Captures information about the type.
type Schema =
{
/// .NET reflected type name (or an F# shorthand where we care)
fullTypeName: string
/// A structural representation of the type rich enough to generate table
/// headers from.
structuralType: FieldType<Schema> list
/// Pattern to match a UI template on for display.
typePattern: TypePattern
}
member this.DisplayName = this.typePattern.DisplayName
type TypedNode = LabelledNode<Schema>
module Reflection =
open Representation
open System.Reflection
open FSharp.Reflection
open System.Collections
type Variant with
static member FromType(typ: Type) =
let ienum = typeof<IEnumerable>
match typ with
| _ when typ = typeof<string> -> Variant.Primitive
| _ when ienum.IsAssignableFrom(typ) -> Variant.Collection
| _ when FSharpType.IsFunction(typ) -> Variant.Function
| _ when FSharpType.IsRecord(typ) -> Variant.Record
| _ when FSharpType.IsTuple(typ) -> Variant.Tuple
| _ when FSharpType.IsUnion(typ) -> Variant.Union
| _ when typ.IsPrimitive -> Variant.Primitive
| _ -> Variant.Poco
let rec generateTypePattern (typ: Type) : TypePattern =
{
typeName = typ.Name
variant = Variant.FromType(typ)
genericTypeArgs =
if typ.IsGenericType then
[ for arg in typ.GenericTypeArguments -> generateTypePattern arg ]
else []
}
let rec generateStructuralType (typ: Type) : FieldType<Schema> list =
let variant = Variant.FromType(typ)
match variant with
| Variant.Record ->
let fields = FSharpType.GetRecordFields(typ, true)
[ for prop in fields -> { name = prop.Name; schema = generateSchema prop.PropertyType } ]
| Variant.Tuple ->
FSharpType.GetTupleElements(typ)
|> Seq.mapi (fun idx e ->
{ name = sprintf "#%d" (idx + 1); schema = generateSchema e })
|> List.ofSeq
| Variant.Collection ->
let argTyp =
if typ.IsGenericType then
Some <| typ.GenericTypeArguments.[0]
elif typ.IsArray then
Some <| typ.GetElementType()
else
None
match argTyp with
| Some t -> generateStructuralType t
| None -> []
| _ -> []
and generateSchema (typ: Type) : Schema =
{
fullTypeName = typ.FullName
structuralType = generateStructuralType typ
typePattern = generateTypePattern typ
}
module TypeShape
open System
open System.Collections.Generic
open System.Runtime.Serialization
open System.Reflection
open Microsoft.FSharp.Reflection
//------------------------------------
// Section: TypeShape core definitions
/// Provides a simple breakdown of basic kinds of types.
/// Used for easier extraction of type shapes in the active pattern implementations.
[<NoEquality; NoComparison>]
type TypeShapeInfo =
| Basic of Type
| Enum of enumTy:Type * underlying:Type
| Array of element:Type * rank:int
| Generic of definition:Type * args:Type []
/// Used to extract the type variable contained in a specific shape
type ITypeShapeVisitor<'R> =
abstract Visit<'T> : unit -> 'R
/// Encapsulates a type variable that can be accessed using type shape visitors
[<AbstractClass>]
type TypeShape =
internal new () = { }
abstract Type : Type
abstract ShapeInfo : TypeShapeInfo
abstract Accept : ITypeShapeVisitor<'R> -> 'R
override s.ToString() = sprintf "TypeShape [%O]" s.Type
/// Encapsulates a type variable that can be accessed using type shape visitors
[<Sealed>]
type TypeShape<'T> () =
inherit TypeShape()
static let shapeInfo =
let t = typeof<'T>
if t.IsEnum then
Enum(t, Enum.GetUnderlyingType t)
elif t.IsArray then
Array(t.GetElementType(), t.GetArrayRank())
elif t.IsGenericType then
Generic(t.GetGenericTypeDefinition(), t.GetGenericArguments())
else
Basic t
override __.Type = typeof<'T>
override __.ShapeInfo = shapeInfo
override __.Accept v = v.Visit<'T> ()
override __.Equals o = o :? TypeShape<'T>
override __.GetHashCode() = hash typeof<'T>
exception UnsupportedShape of Type:Type
with
override __.Message = sprintf "Unsupported TypeShape '%O'" __.Type
[<AutoOpen>]
module private TypeShapeImpl =
let fsharpCoreRuntimeVersion =
typeof<unit>.Assembly.GetName().Version
let fsharpCore41Version = Version(4,4,1,0)
let allMembers =
BindingFlags.NonPublic ||| BindingFlags.Public |||
BindingFlags.Instance ||| BindingFlags.Static |||
BindingFlags.FlattenHierarchy
let allInstanceMembers =
BindingFlags.NonPublic ||| BindingFlags.Public ||| BindingFlags.Instance
type MemberInfo with
member inline m.ContainsAttr<'Attr when 'Attr :> Attribute> (inheritAttr) =
m.GetCustomAttributes(inheritAttr)
|> Array.exists (function :? 'Attr -> true | _ -> false)
member inline m.TryGetAttribute<'Attr when 'Attr :> Attribute> (inheritAttr) =
m.GetCustomAttributes(inheritAttr)
|> Array.tryPick (function :? 'Attr as attr -> Some attr | _ -> None)
let activateGeneric (templateTy:Type) (typeArgs : Type[]) (args:obj[]) =
let templateTy =
if typeArgs.Length = 0 then templateTy
elif not templateTy.IsGenericType then invalidArg (string templateTy) "not generic."
elif not templateTy.IsGenericTypeDefinition then
templateTy.GetGenericTypeDefinition().MakeGenericType typeArgs
else
templateTy.MakeGenericType typeArgs
let ctypes = args |> Array.map (fun o -> o.GetType())
let ctor = templateTy.GetConstructor(allMembers, null, CallingConventions.Standard, ctypes, [||])
ctor.Invoke args
/// correctly resolves if type is assignable to interface
let rec isInterfaceAssignableFrom (iface : Type) (ty : Type) =
let proj (t : Type) = t.Assembly, t.Namespace, t.Name, t.MetadataToken
if iface = ty then true
elif ty.GetInterfaces() |> Array.exists(fun if0 -> proj if0 = proj iface) then true
else
match ty.BaseType with
| null -> false
| bt -> isInterfaceAssignableFrom iface bt
let private canon = Type.GetType "System.__Canon"
let private genShapeTy = typedefof<TypeShape<_>>
let resolveTypeShape(typ : Type) =
if typ = null then raise <| ArgumentNullException("TypeShape: System.Type cannot be null.")
if typ.IsGenericTypeDefinition then raise <| UnsupportedShape typ
elif typ.IsGenericParameter then raise <| UnsupportedShape typ
elif typ = canon then raise <| UnsupportedShape typ
elif typ.IsByRef || typ.IsPointer then raise <| UnsupportedShape typ
else
let gt = genShapeTy.MakeGenericType [|typ|]
Activator.CreateInstance gt :?> TypeShape
type Activator with
/// Generic edition of the activator method which support type parameters and private types
static member CreateInstanceGeneric<'Template>(?typeArgs : Type[], ?args:obj[]) : obj =
let typeArgs = defaultArg typeArgs [||]
let args = defaultArg args [||]
activateGeneric typeof<'Template> typeArgs args
type Type with
/// Correctly resolves if type is assignable to interface
member iface.IsInterfaceAssignableFrom(ty : Type) : bool =
isInterfaceAssignableFrom iface ty
type TypeShape with
/// <summary>
/// Creates a type shape instance for given type
/// </summary>
/// <param name="typ">System.Type to be resolved.</param>
static member Create(typ : Type) : TypeShape = resolveTypeShape typ
/// <summary>
/// Creates a type shape instance from the underlying
/// type of a given value.
/// </summary>
/// <param name="obj">Non-null value to extract shape data from.</param>
static member FromValue(obj : obj) : TypeShape =
match obj with
| null -> raise <| ArgumentNullException()
| obj -> resolveTypeShape (obj.GetType())
/// <summary>
/// Creates a type shape instance for given type
/// </summary>
static member Create<'T>() : TypeShape<'T> = new TypeShape<'T>()
/// Creates a type shape instance for given type
let shapeof<'T> = TypeShape.Create<'T>() :> TypeShape
/// Typed variation of the shapeof operator
let tshapeof<'T> = TypeShape.Create<'T>()
//------------------------
// Section: Core BCL types
// Enum types
type IEnumVisitor<'R> =
abstract Visit<'Enum, 'Underlying when 'Enum : enum<'Underlying>
and 'Enum : struct
and 'Enum :> ValueType
and 'Enum : (new : unit -> 'Enum)> : unit -> 'R
type IShapeEnum =
abstract Underlying : TypeShape
abstract Accept : IEnumVisitor<'R> -> 'R
type private ShapeEnum<'Enum, 'Underlying when 'Enum : enum<'Underlying>
and 'Enum : struct
and 'Enum :> ValueType
and 'Enum : (new : unit -> 'Enum)>() =
interface IShapeEnum with
member __.Underlying = shapeof<'Underlying>
member __.Accept v = v.Visit<'Enum, 'Underlying> ()
// Nullable types
type INullableVisitor<'R> =
abstract Visit<'T when 'T : (new : unit -> 'T) and 'T :> ValueType and 'T : struct> : unit -> 'R
type IShapeNullable =
abstract Element : TypeShape
abstract Accept : INullableVisitor<'R> -> 'R
type private ShapeNullable<'T when 'T : (new : unit -> 'T) and 'T :> ValueType and 'T : struct> () =
interface IShapeNullable with
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'T> ()
// Default Constructor types
type IDefaultConstructorVisitor<'R> =
abstract Visit<'T when 'T : (new : unit -> 'T)> : unit -> 'R
type IShapeDefaultConstructor =
abstract Accept : IDefaultConstructorVisitor<'R> -> 'R
type private ShapeDefaultConstructor<'T when 'T : (new : unit -> 'T)>() =
interface IShapeDefaultConstructor with
member __.Accept v = v.Visit<'T>()
// Equality Types
type IEqualityVisitor<'R> =
abstract Visit<'T when 'T : equality> : unit -> 'R
type IShapeEquality =
abstract Accept : IEqualityVisitor<'R> -> 'R
type private ShapeEquality<'T when 'T : equality>() =
interface IShapeEquality with
member __.Accept v = v.Visit<'T>()
// Comparison Types
type IComparisonVisitor<'R> =
abstract Visit<'T when 'T : comparison> : unit -> 'R
type IShapeComparison =
abstract Accept : IComparisonVisitor<'R> -> 'R
type private ShapeComparison<'T when 'T : comparison>() =
interface IShapeComparison with
member __.Accept v = v.Visit<'T>()
// Struct Types
type IStructVisitor<'R> =
abstract Visit<'T when 'T : struct> : unit -> 'R
type IShapeStruct =
abstract Accept : IStructVisitor<'R> -> 'R
type private ShapeStruct<'T when 'T : struct>() =
interface IShapeStruct with
member __.Accept v = v.Visit<'T>()
// Reference Types
type INotStructVisitor<'R> =
abstract Visit<'T when 'T : not struct and 'T : null> : unit -> 'R
type IShapeNotStruct =
abstract Accept : INotStructVisitor<'R> -> 'R
type private ShapeNotStruct<'T when 'T : not struct and 'T : null>() =
interface IShapeNotStruct with
member __.Accept v = v.Visit<'T>()
// Delegates
type IDelegateVisitor<'R> =
abstract Visit<'Delegate when 'Delegate :> Delegate> : unit -> 'R
type IShapeDelegate =
abstract Accept : IDelegateVisitor<'R> -> 'R
type private ShapeDelegate<'Delegate when 'Delegate :> Delegate>() =
interface IShapeDelegate with
member __.Accept v = v.Visit<'Delegate>()
// System.Tuple`1
type ITuple1Visitor<'R> =
abstract Visit<'T> : unit -> 'R
type IShapeTuple1 =
abstract Item1 : TypeShape
abstract Accept : ITuple1Visitor<'R> -> 'R
type private ShapeTuple1<'T> () =
interface IShapeTuple1 with
member __.Item1 = shapeof<'T>
member __.Accept v = v.Visit<'T> ()
// System.Tuple`2
type ITuple2Visitor<'R> =
abstract Visit<'T1, 'T2> : unit -> 'R
type IShapeTuple2 =
abstract Item1 : TypeShape
abstract Item2 : TypeShape
abstract Accept : ITuple2Visitor<'R> -> 'R
type private ShapeTuple2<'T1, 'T2> () =
interface IShapeTuple2 with
member __.Item1 = shapeof<'T1>
member __.Item2 = shapeof<'T2>
member __.Accept v = v.Visit<'T1,'T2> ()
// System.Tuple`3
type ITuple3Visitor<'R> =
abstract Visit<'T1, 'T2, 'T3> : unit -> 'R
type IShapeTuple3 =
abstract Item1 : TypeShape
abstract Item2 : TypeShape
abstract Item3 : TypeShape
abstract Accept : ITuple3Visitor<'R> -> 'R
type private ShapeTuple3<'T1, 'T2, 'T3> () =
interface IShapeTuple3 with
member __.Item1 = shapeof<'T1>
member __.Item2 = shapeof<'T2>
member __.Item3 = shapeof<'T3>
member __.Accept v = v.Visit<'T1, 'T2, 'T3> ()
// System.Tuple`4
type ITuple4Visitor<'R> =
abstract Visit<'T1, 'T2, 'T3, 'T4> : unit -> 'R
type IShapeTuple4 =
abstract Item1 : TypeShape
abstract Item2 : TypeShape
abstract Item3 : TypeShape
abstract Item4 : TypeShape
abstract Accept : ITuple4Visitor<'R> -> 'R
type private ShapeTuple4<'T1, 'T2, 'T3, 'T4> () =
interface IShapeTuple4 with
member __.Item1 = shapeof<'T1>
member __.Item2 = shapeof<'T2>
member __.Item3 = shapeof<'T3>
member __.Item4 = shapeof<'T4>
member __.Accept v = v.Visit<'T1, 'T2, 'T3, 'T4> ()
// System.Tuple`5
type ITuple5Visitor<'R> =
abstract Visit<'T1, 'T2, 'T3, 'T4, 'T5> : unit -> 'R
type IShapeTuple5 =
abstract Item1 : TypeShape
abstract Item2 : TypeShape
abstract Item3 : TypeShape
abstract Item4 : TypeShape
abstract Item5 : TypeShape
abstract Accept : ITuple5Visitor<'R> -> 'R
type private ShapeTuple5<'T1, 'T2, 'T3, 'T4, 'T5> () =
interface IShapeTuple5 with
member __.Item1 = shapeof<'T1>
member __.Item2 = shapeof<'T2>
member __.Item3 = shapeof<'T3>
member __.Item4 = shapeof<'T4>
member __.Item5 = shapeof<'T5>
member __.Accept v = v.Visit<'T1, 'T2, 'T3, 'T4, 'T5> ()
// System.Tuple`6
type ITuple6Visitor<'R> =
abstract Visit<'T1, 'T2, 'T3, 'T4, 'T5, 'T6> : unit -> 'R
type IShapeTuple6 =
abstract Item1 : TypeShape
abstract Item2 : TypeShape
abstract Item3 : TypeShape
abstract Item4 : TypeShape
abstract Item5 : TypeShape
abstract Item6 : TypeShape
abstract Accept : ITuple6Visitor<'R> -> 'R
type private ShapeTuple6<'T1, 'T2, 'T3, 'T4, 'T5, 'T6> () =
interface IShapeTuple6 with
member __.Item1 = shapeof<'T1>
member __.Item2 = shapeof<'T2>
member __.Item3 = shapeof<'T3>
member __.Item4 = shapeof<'T4>
member __.Item5 = shapeof<'T5>
member __.Item6 = shapeof<'T6>
member __.Accept v = v.Visit<'T1, 'T2, 'T3, 'T4, 'T5, 'T6> ()
// System.Tuple`7
type ITuple7Visitor<'R> =
abstract Visit<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7> : unit -> 'R
type IShapeTuple7 =
abstract Item1 : TypeShape
abstract Item2 : TypeShape
abstract Item3 : TypeShape
abstract Item4 : TypeShape
abstract Item5 : TypeShape
abstract Item6 : TypeShape
abstract Item7 : TypeShape
abstract Accept : ITuple7Visitor<'R> -> 'R
type private ShapeTuple7<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7> () =
interface IShapeTuple7 with
member __.Item1 = shapeof<'T1>
member __.Item2 = shapeof<'T2>
member __.Item3 = shapeof<'T3>
member __.Item4 = shapeof<'T4>
member __.Item5 = shapeof<'T5>
member __.Item6 = shapeof<'T6>
member __.Item7 = shapeof<'T7>
member __.Accept v = v.Visit<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7> ()
// System.Tuple`8
type ITuple8Visitor<'R> =
abstract Visit<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'TRest> : unit -> 'R
type IShapeTuple8 =
abstract Item1 : TypeShape
abstract Item2 : TypeShape
abstract Item3 : TypeShape
abstract Item4 : TypeShape
abstract Item5 : TypeShape
abstract Item6 : TypeShape
abstract Item7 : TypeShape
abstract Rest : TypeShape
abstract Accept : ITuple8Visitor<'R> -> 'R
type private ShapeTuple8<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'TRest> () =
interface IShapeTuple8 with
member __.Item1 = shapeof<'T1>
member __.Item2 = shapeof<'T2>
member __.Item3 = shapeof<'T3>
member __.Item4 = shapeof<'T4>
member __.Item5 = shapeof<'T5>
member __.Item6 = shapeof<'T6>
member __.Item7 = shapeof<'T7>
member __.Rest = shapeof<'TRest>
member __.Accept v = v.Visit<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'TRest> ()
// F# functions
type IFSharpFuncVisitor<'R> =
abstract Visit<'Domain, 'CoDomain> : unit -> 'R
type IShapeFSharpFunc =
abstract Domain : TypeShape
abstract CoDomain : TypeShape
abstract Accept : IFSharpFuncVisitor<'R> -> 'R
type private ShapeFSharpFunc<'Domain, 'CoDomain> () =
interface IShapeFSharpFunc with
member __.Domain = shapeof<'Domain>
member __.CoDomain = shapeof<'CoDomain>
member __.Accept v = v.Visit<'Domain, 'CoDomain> ()
// System.Exception
type IExceptionVisitor<'R> =
abstract Visit<'exn when 'exn :> exn and 'exn : not struct and 'exn : null> : unit -> 'R
type IShapeException =
abstract IsFSharpException : bool
abstract Accept : IExceptionVisitor<'R> -> 'R
type private ShapeException<'exn when 'exn :> exn and 'exn : not struct and 'exn : null> (isFSharpExn : bool) =
interface IShapeException with
member __.IsFSharpException = isFSharpExn
member __.Accept v = v.Visit<'exn> ()
//-----------------------------------
// Section: Collections & IEnumerable
// IEnumerable
type IEnumerableVisitor<'R> =
abstract Visit<'Enum, 'T when 'Enum :> seq<'T>> : unit -> 'R
type IShapeEnumerable =
abstract Element : TypeShape
abstract Accept : IEnumerableVisitor<'R> -> 'R
type private ShapeEnumerable<'Enum, 'T when 'Enum :> seq<'T>> () =
interface IShapeEnumerable with
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'Enum, 'T> ()
// Collection
type ICollectionVisitor<'R> =
abstract Visit<'Collection, 'T when 'Collection :> ICollection<'T>> : unit -> 'R
type IShapeCollection =
abstract Element : TypeShape
abstract Accept : ICollectionVisitor<'R> -> 'R
type private ShapeCollection<'Collection, 'T when 'Collection :> ICollection<'T>> () =
interface IShapeCollection with
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'Collection, 'T> ()
// KeyValuePair
type IKeyValuePairVisitor<'R> =
abstract Visit<'K, 'V> : unit -> 'R
type IShapeKeyValuePair =
abstract Key : TypeShape
abstract Value : TypeShape
abstract Accept : IKeyValuePairVisitor<'R> -> 'R
type private ShapeKeyValuePair<'K,'V> () =
interface IShapeKeyValuePair with
member __.Key = shapeof<'K>
member __.Value = shapeof<'V>
member __.Accept v = v.Visit<'K, 'V> ()
// System.Array
type IArrayVisitor<'R> =
abstract Visit<'T> : rank:int -> 'R
type IShapeArray =
/// Gets the rank of the array type shape
abstract Rank : int
abstract Element : TypeShape
abstract Accept : IArrayVisitor<'R> -> 'R
type private ShapeArray<'T>(rank : int) =
/// Gets the rank of the array type shape
member __.Rank = rank
interface IShapeArray with
member __.Rank = rank
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'T> rank
type ISystemArrayVisitor<'R> =
abstract Visit<'Array when 'Array :> System.Array> : unit -> 'R
type IShapeSystemArray =
abstract Rank : int
abstract Element : TypeShape
abstract Accept : ISystemArrayVisitor<'R> -> 'R
type private ShapeSystemArray<'Array when 'Array :> System.Array>(elem : Type, rank : int) =
interface IShapeSystemArray with
member __.Rank = rank
member __.Element = TypeShape.Create elem
member __.Accept v = v.Visit<'Array> ()
// System.Collections.List
type IResizeArrayVisitor<'R> =
abstract Visit<'T> : unit -> 'R
type IShapeResizeArray =
abstract Element : TypeShape
abstract Accept : IResizeArrayVisitor<'R> -> 'R
type private ShapeResizeArray<'T> () =
interface IShapeResizeArray with
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'T> ()
// System.Collections.Dictionary
type IDictionaryVisitor<'R> =
abstract Visit<'K, 'V when 'K : equality> : unit -> 'R
type IShapeDictionary =
abstract Key : TypeShape
abstract Value : TypeShape
abstract Accept : IDictionaryVisitor<'R> -> 'R
type private ShapeDictionary<'K, 'V when 'K : equality> () =
interface IShapeDictionary with
member __.Key = shapeof<'K>
member __.Value = shapeof<'V>
member __.Accept v = v.Visit<'K, 'V> ()
// System.Collections.HashSet
type IHashSetVisitor<'R> =
abstract Visit<'T when 'T : equality> : unit -> 'R
type IShapeHashSet =
abstract Element : TypeShape
abstract Accept : IHashSetVisitor<'R> -> 'R
type private ShapeHashSet<'T when 'T : equality> () =
interface IShapeHashSet with
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'T> ()
// F# Set
type IFSharpSetVisitor<'R> =
abstract Visit<'T when 'T : comparison> : unit -> 'R
type IShapeFSharpSet =
abstract Element : TypeShape
abstract Accept : IFSharpSetVisitor<'R> -> 'R
type private ShapeFSharpSet<'T when 'T : comparison> () =
interface IShapeFSharpSet with
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'T> ()
// F# Map
type IFSharpMapVisitor<'R> =
abstract Visit<'K, 'V when 'K : comparison> : unit -> 'R
type IShapeFSharpMap =
abstract Key : TypeShape
abstract Value : TypeShape
abstract Accept : IFSharpMapVisitor<'R> -> 'R
type private ShapeFSharpMap<'K, 'V when 'K : comparison> () =
interface IShapeFSharpMap with
member __.Key = shapeof<'K>
member __.Value = shapeof<'V>
member __.Accept v = v.Visit<'K, 'V>()
// F# ref
type IShapeFSharpRef =
abstract Element : TypeShape
abstract Accept : IFSharpRefVisitor<'R> -> 'R
and IFSharpRefVisitor<'R> =
abstract Visit<'T> : unit -> 'R
type private ShapeFSharpRef<'T> () =
interface IShapeFSharpRef with
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'T> ()
// F# option
type IFSharpOptionVisitor<'R> =
abstract Visit<'T> : unit -> 'R
type IShapeFSharpOption =
abstract Element : TypeShape
abstract Accept : IFSharpOptionVisitor<'R> -> 'R
type private ShapeFSharpOption<'T> () =
interface IShapeFSharpOption with
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'T> ()
// F# List
type IFSharpListVisitor<'R> =
abstract Visit<'T> : unit -> 'R
type IShapeFSharpList =
abstract Element : TypeShape
abstract Accept : IFSharpListVisitor<'R> -> 'R
type private ShapeFSharpList<'T> () =
interface IShapeFSharpList with
member __.Element = shapeof<'T>
member __.Accept v = v.Visit<'T> ()
// F# Choice`2
type IFSharpChoice2Visitor<'R> =
abstract Visit<'T1,'T2> : unit -> 'R
type IShapeFSharpChoice2 =
abstract Type1 : TypeShape
abstract Type2 : TypeShape
abstract Accept : IFSharpChoice2Visitor<'R> -> 'R
type private ShapeFSharpChoice<'T1, 'T2> () =
interface IShapeFSharpChoice2 with
member __.Type1 = shapeof<'T1>
member __.Type2 = shapeof<'T2>
member __.Accept v = v.Visit<'T1,'T2>()
// F# Choice`3
type IFSharpChoice3Visitor<'R> =
abstract Visit<'T1,'T2,'T3> : unit -> 'R
type IShapeFSharpChoice3 =
abstract Type1 : TypeShape
abstract Type2 : TypeShape
abstract Type3 : TypeShape
abstract Accept : IFSharpChoice3Visitor<'R> -> 'R
type private ShapeFSharpChoice<'T1, 'T2, 'T3> () =
interface IShapeFSharpChoice3 with
member __.Type1 = shapeof<'T1>
member __.Type2 = shapeof<'T2>
member __.Type3 = shapeof<'T3>
member __.Accept v = v.Visit<'T1,'T2,'T3>()
// F# Choice`4
type IFSharpChoice4Visitor<'R> =
abstract Visit<'T1,'T2,'T3,'T4> : unit -> 'R
type IShapeFSharpChoice4 =
abstract Type1 : TypeShape
abstract Type2 : TypeShape
abstract Type3 : TypeShape
abstract Type4 : TypeShape
abstract Accept : IFSharpChoice4Visitor<'R> -> 'R
type private ShapeFSharpChoice<'T1, 'T2, 'T3, 'T4> () =
interface IShapeFSharpChoice4 with
member __.Type1 = shapeof<'T1>
member __.Type2 = shapeof<'T2>
member __.Type3 = shapeof<'T3>
member __.Type4 = shapeof<'T4>
member __.Accept v = v.Visit<'T1,'T2,'T3,'T4>()
// F# Choice`5
type IFSharpChoice5Visitor<'R> =
abstract Visit<'T1,'T2,'T3,'T4,'T5> : unit -> 'R
type IShapeFSharpChoice5 =
abstract Type1 : TypeShape
abstract Type2 : TypeShape
abstract Type3 : TypeShape
abstract Type4 : TypeShape
abstract Type5 : TypeShape
abstract Accept : IFSharpChoice5Visitor<'R> -> 'R
type private ShapeFSharpChoice<'T1, 'T2, 'T3, 'T4, 'T5> () =
interface IShapeFSharpChoice5 with
member __.Type1 = shapeof<'T1>
member __.Type2 = shapeof<'T2>
member __.Type3 = shapeof<'T3>
member __.Type4 = shapeof<'T4>
member __.Type5 = shapeof<'T5>
member __.Accept v = v.Visit<'T1,'T2,'T3,'T4,'T5>()
// F# Choice`6
type IFSharpChoice6Visitor<'R> =
abstract Visit<'T1,'T2,'T3,'T4,'T5,'T6> : unit -> 'R
type IShapeFSharpChoice6 =
abstract Type1 : TypeShape
abstract Type2 : TypeShape
abstract Type3 : TypeShape
abstract Type4 : TypeShape
abstract Type5 : TypeShape
abstract Type6 : TypeShape
abstract Accept : IFSharpChoice6Visitor<'R> -> 'R
type private ShapeFSharpChoice<'T1, 'T2, 'T3, 'T4, 'T5, 'T6> () =
interface IShapeFSharpChoice6 with
member __.Type1 = shapeof<'T1>
member __.Type2 = shapeof<'T2>
member __.Type3 = shapeof<'T3>
member __.Type4 = shapeof<'T4>
member __.Type5 = shapeof<'T5>
member __.Type6 = shapeof<'T6>
member __.Accept v = v.Visit<'T1,'T2,'T3,'T4,'T5,'T6>()
// F# Choice`7
type IFSharpChoice7Visitor<'R> =
abstract Visit<'T1,'T2,'T3,'T4,'T5,'T6,'T7> : unit -> 'R
type IShapeFSharpChoice7 =
abstract Type1 : TypeShape
abstract Type2 : TypeShape
abstract Type3 : TypeShape
abstract Type4 : TypeShape
abstract Type5 : TypeShape
abstract Type6 : TypeShape
abstract Type7 : TypeShape
abstract Accept : IFSharpChoice7Visitor<'R> -> 'R
type private ShapeFSharpChoice<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7> () =
interface IShapeFSharpChoice7 with
member __.Type1 = shapeof<'T1>
member __.Type2 = shapeof<'T2>
member __.Type3 = shapeof<'T3>
member __.Type4 = shapeof<'T4>
member __.Type5 = shapeof<'T5>
member __.Type6 = shapeof<'T6>
member __.Type7 = shapeof<'T7>
member __.Accept v = v.Visit<'T1,'T2,'T3,'T4,'T5,'T6,'T7>()
//-----------------------------