You've already forked linux-packaging-mono
Imported Upstream version 6.6.0.89
Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
This commit is contained in:
parent
cf815e07e0
commit
95fdb59ea6
66
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/AbstractClasses.fs
vendored
Normal file
66
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/AbstractClasses.fs
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
module AbstractClasses
|
||||
|
||||
// An abstract class that has some methods and properties defined
|
||||
// and some left abstract.
|
||||
[<AbstractClass>]
|
||||
type Shape2D(x0 : float, y0 : float) =
|
||||
let mutable x, y = x0, y0
|
||||
let mutable rotAngle = 0.0
|
||||
|
||||
// These properties are not declared abstract. They
|
||||
// cannot be overriden.
|
||||
member this.CenterX with get() = x and set xval = x <- xval
|
||||
|
||||
// These properties are abstract, and no default implementation
|
||||
// is provided. Non-abstract derived classes must implement these.
|
||||
abstract Area : float with get
|
||||
|
||||
// This method is not declared abstract. It cannot be
|
||||
// overriden.
|
||||
member this.Move dx dy =
|
||||
x <- x + dx
|
||||
y <- y + dy
|
||||
|
||||
|
||||
// An abstract method that is given a default implementation
|
||||
// is equivalent to a virtual method in other .NET languages.
|
||||
// Rotate changes the internal angle of rotation of the square.
|
||||
// Angle is assumed to be in degrees.
|
||||
abstract member Rotate: float -> unit
|
||||
default this.Rotate(angle) = rotAngle <- rotAngle + angle
|
||||
|
||||
abstract member Rotate2: float -> unit
|
||||
member this.Rotate3: float -> unit = fun(ff) -> ()
|
||||
|
||||
|
||||
|
||||
type Square(x, y, sideLengthIn) =
|
||||
inherit Shape2D(x, y)
|
||||
member this.SideLength = sideLengthIn
|
||||
override this.Area = this.SideLength * this.SideLength
|
||||
override this.Rotate2(angle) = ()
|
||||
|
||||
type Circle(x, y, radius) =
|
||||
inherit Shape2D(x, y)
|
||||
let PI = 3.141592654
|
||||
member this.Radius = radius
|
||||
override this.Area = PI * this.Radius * this.Radius
|
||||
// Rotating a circle does nothing, so use the wildcard
|
||||
// character to discard the unused argument and
|
||||
// evaluate to unit.
|
||||
override this.Rotate(_) = ()
|
||||
//override this.Name = "Circle"
|
||||
override this.Rotate2(angle) = ()
|
||||
|
||||
let square1 = new Square(0.0, 0.0, 10.0)
|
||||
let circle1 = new Circle(0.0, 0.0, 5.0)
|
||||
circle1.CenterX <- 1.0
|
||||
square1.Move -1.0 2.0
|
||||
square1.Rotate 45.0
|
||||
circle1.Rotate 45.0
|
||||
|
||||
let shapeList : list<Shape2D> = [ (square1 :> Shape2D);
|
||||
(circle1 :> Shape2D) ]
|
||||
List.iter (fun (elem : Shape2D) ->
|
||||
printfn "Area of %s: %f" (elem.ToString()) (elem.Area))
|
||||
shapeList
|
28
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Accessibility.fs
vendored
Normal file
28
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Accessibility.fs
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
module Accessibility
|
||||
|
||||
// This type is not usable outside of this file
|
||||
type private MyPrivateType() =
|
||||
// x is private since this is an internal let binding
|
||||
let x = 5
|
||||
// X is private and does not appear in the QuickInfo window
|
||||
// when viewing this type in the Visual Studio editor
|
||||
member private this.X() = 10
|
||||
member this.Z() = x * 100
|
||||
|
||||
type internal MyInternalType() =
|
||||
let x = 5
|
||||
member private this.X() = 10
|
||||
member this.Z() = x * 100
|
||||
|
||||
// Top-level let bindings are public by default,
|
||||
// so "private" and "internal" are needed here since a
|
||||
// value cannot be more accessible than its type.
|
||||
let private myPrivateObj = new MyPrivateType()
|
||||
let internal myInternalObj = new MyInternalType()
|
||||
|
||||
// let bindings at the top level are public by default,
|
||||
// so result1 and result2 are public.
|
||||
let result1 = myPrivateObj.Z
|
||||
let result2 = myInternalObj.Z
|
||||
|
||||
|
10
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/AccessibilityTest.fs
vendored
Normal file
10
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/AccessibilityTest.fs
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
module AccessibilityTest
|
||||
|
||||
open Accessibility
|
||||
|
||||
// The following line is an error because private means
|
||||
// that it cannot be accessed from another file or module
|
||||
// let private myPrivateObj = new MyPrivateType()
|
||||
let internal myInternalObj = new MyInternalType()
|
||||
|
||||
let result = myInternalObj.Z
|
17
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Animals.fs
vendored
Normal file
17
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Animals.fs
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
module Animals
|
||||
|
||||
// Call a base class from a derived one.
|
||||
type Animal() =
|
||||
member __.Rest() = ()
|
||||
|
||||
type Dog() =
|
||||
inherit Animal()
|
||||
member __.Run() =
|
||||
base.Rest()
|
||||
|
||||
// Upcasting is denoted by :> operator.
|
||||
let dog = Dog()
|
||||
let animal = dog :> Animal
|
||||
|
||||
//Dynamic downcasting (:?>) might throw an InvalidCastException if the cast doesn't succeed at runtime.
|
||||
let shouldBeADog = animal :?> Dog
|
41
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/AssemblyInfo.fs
vendored
Normal file
41
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/AssemblyInfo.fs
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
namespace mdoc.Test.FSharp.AssemblyInfo
|
||||
|
||||
open System.Reflection
|
||||
open System.Runtime.CompilerServices
|
||||
open System.Runtime.InteropServices
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[<assembly: AssemblyTitle("mdoc.Test.FSharp")>]
|
||||
[<assembly: AssemblyDescription("")>]
|
||||
[<assembly: AssemblyConfiguration("")>]
|
||||
[<assembly: AssemblyCompany("EPAM Systems")>]
|
||||
[<assembly: AssemblyProduct("mdoc.Test.FSharp")>]
|
||||
[<assembly: AssemblyCopyright("Copyright © EPAM Systems 2017")>]
|
||||
[<assembly: AssemblyTrademark("")>]
|
||||
[<assembly: AssemblyCulture("")>]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[<assembly: ComVisible(false)>]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[<assembly: Guid("979f9f80-12fe-4236-9e93-6d554ab13701")>]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [<assembly: AssemblyVersion("1.0.*")>]
|
||||
[<assembly: AssemblyVersion("1.0.0.0")>]
|
||||
[<assembly: AssemblyFileVersion("1.0.0.0")>]
|
||||
|
||||
do
|
||||
()
|
22
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Attributes.fs
vendored
Normal file
22
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Attributes.fs
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
module Attributes
|
||||
|
||||
open System
|
||||
|
||||
|
||||
type OwnerAttribute(name : string) =
|
||||
inherit System.Attribute()
|
||||
|
||||
type CompanyAttribute(name : string) =
|
||||
inherit System.Attribute()
|
||||
|
||||
|
||||
[<Owner("Jason Carlson")>]
|
||||
[<Company("Microsoft")>]
|
||||
type SomeType1 = class end
|
||||
|
||||
|
||||
|
||||
[<AttributeUsage(AttributeTargets.Event ||| AttributeTargets.Module ||| AttributeTargets.Delegate, AllowMultiple = false)>]
|
||||
type TypeWithFlagAttribute = class
|
||||
member this.X = "F#"
|
||||
end
|
27
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/ClassMembers.fs
vendored
Normal file
27
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/ClassMembers.fs
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
module ClassMembers
|
||||
|
||||
type PointWithCounter(a: int, b: int) =
|
||||
// A variable i.
|
||||
let mutable i = 0
|
||||
|
||||
// A let binding that uses a pattern.
|
||||
let (x, y) = (a, b)
|
||||
|
||||
// A private function binding.
|
||||
let privateFunction x y = x * x + 2*y
|
||||
|
||||
// A static let binding.
|
||||
static let mutable count = 0
|
||||
|
||||
// A do binding.
|
||||
do
|
||||
count <- count + 1
|
||||
|
||||
member this.Prop1 = x
|
||||
member this.Prop2 = y
|
||||
member this.CreatedCount = count
|
||||
member this.FunctionValue = privateFunction x y
|
||||
|
||||
let point1 = PointWithCounter(10, 52)
|
||||
|
||||
printfn "%d %d %d %d" (point1.Prop1) (point1.Prop2) (point1.CreatedCount) (point1.FunctionValue)
|
18
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Collections.fs
vendored
Normal file
18
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Collections.fs
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
module Collections
|
||||
open FSharp.Collections
|
||||
open System
|
||||
open System.Collections
|
||||
open System.Collections.Generic
|
||||
|
||||
let f (x:Map<int, int>) = 0
|
||||
|
||||
let f2 (x:seq<int>) = 0
|
||||
|
||||
type MDocInterface<'key> = interface
|
||||
end
|
||||
|
||||
type MDocTestMap<'Key, 'Value> = class
|
||||
interface MDocInterface<KeyValuePair<'Key, 'Value>>
|
||||
|
||||
|
||||
end
|
90
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Constraints.fs
vendored
Normal file
90
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Constraints.fs
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
module Constraints
|
||||
|
||||
// Base Type Constraint
|
||||
type Class1<'T when 'T :> System.Exception>() =
|
||||
class end
|
||||
|
||||
// Interface Type Constraint
|
||||
type Class2<'T when 'T :> System.IComparable>() =
|
||||
class end
|
||||
|
||||
// Interface Type Constraint
|
||||
type Class2_1<'T when 'T :> System.IComparable and 'T :> System.Exception>() =
|
||||
class end
|
||||
|
||||
// Interface Type Constraint with recursion
|
||||
type Class2_2<'T when 'T :> System.IComparable and 'T :> seq<'T>>() =
|
||||
class end
|
||||
|
||||
// Null constraint
|
||||
type Class3<'T when 'T : null>() =
|
||||
class end
|
||||
|
||||
// Member constraint with static member
|
||||
type Class4<'T when 'T : (static member staticMethod1 : unit -> 'T) >() =
|
||||
class end
|
||||
|
||||
// Member constraint with instance member
|
||||
type Class5<'T when 'T : (member Method1 : 'T -> int)>() =
|
||||
class end
|
||||
|
||||
// Member constraint with property
|
||||
type Class6<'T when 'T : (member Property1 : int)>() =
|
||||
class end
|
||||
|
||||
// Constructor constraint
|
||||
type Class7<'T when 'T : (new : unit -> 'T)>() =
|
||||
class end
|
||||
//member val Field = new 'T()
|
||||
|
||||
// Reference type constraint
|
||||
type Class8<'T when 'T : not struct>() =
|
||||
class end
|
||||
|
||||
// Enumeration constraint with underlying value specified
|
||||
type Class9<'T when 'T : enum<uint32>>() =
|
||||
class end
|
||||
|
||||
// 'T must implement IComparable, or be an array type with comparable
|
||||
// elements, or be System.IntPtr or System.UIntPtr. Also, 'T must not have
|
||||
// the NoComparison attribute.
|
||||
type Class10<'T when 'T : comparison>() =
|
||||
class end
|
||||
|
||||
// 'T must support equality. This is true for any type that does not
|
||||
// have the NoEquality attribute.
|
||||
type Class11<'T when 'T : equality>() =
|
||||
class end
|
||||
|
||||
type Class12<'T when 'T : delegate<obj * System.EventArgs, unit>>() =
|
||||
class end
|
||||
|
||||
type Class13<'T when 'T : unmanaged>() =
|
||||
class end
|
||||
|
||||
// If there are multiple constraints, use the and keyword to separate them.
|
||||
type Class14<'T,'U when 'T : equality and 'U : equality>() =
|
||||
class end
|
||||
|
||||
type Class15() = class
|
||||
// Member constraints with two type parameters
|
||||
// Most often used with static type parameters in inline functions
|
||||
static member inline add(value1 : ^T when ^T : (static member (+) : ^T * ^T -> ^T), value2: ^T) =
|
||||
value1 + value2
|
||||
|
||||
// ^T and ^U must support operator +
|
||||
static member inline heterogenousAdd(value1 : ^T when (^T or ^U) : (static member (+) : ^T * ^U -> ^T), value2 : ^U) =
|
||||
value1 + value2
|
||||
end
|
||||
|
||||
type Class16() = class
|
||||
static member inline method(value1 : ^T when ^T : (static member (+) : ^T * ^T -> ^T), value2: ^T) = ()
|
||||
end
|
||||
|
||||
type Class17() = class
|
||||
static member method<'T when 'T : null>(value1 : 'T, value2: 'T) = ()
|
||||
end
|
||||
|
||||
type Class18() = class
|
||||
static member method(value1 : ^T, value2: ^T) = ()
|
||||
end
|
315
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Constructors.fs
vendored
Normal file
315
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Constructors.fs
vendored
Normal file
@@ -0,0 +1,315 @@
|
||||
module Constructors
|
||||
|
||||
type MyClass(x0, y0, z0) =
|
||||
let mutable x = x0
|
||||
let mutable y = y0
|
||||
let mutable z = z0
|
||||
do
|
||||
printfn "Initialized object that has coordinates (%d, %d, %d)" x y z
|
||||
member this.X with get() = x and set(value) = x <- value
|
||||
member this.Y with get() = y and set(value) = y <- value
|
||||
member this.Z with get() = z and set(value) = z <- value
|
||||
new() = MyClass(0, 0, 0)
|
||||
|
||||
type MyClassObjectParameters(x0:string, y0, z0) =
|
||||
let mutable x = x0
|
||||
let mutable y = y0
|
||||
let mutable z = z0
|
||||
member this.X with get() = x and set(value) = x <- value
|
||||
member this.Y with get() = y and set(value) = y <- value
|
||||
member internal this.Z with get() = z and set(value) = z <- value
|
||||
|
||||
// new() = MyClassObjectParameters("", 0, 0)
|
||||
// new(x0:string) = MyClassObjectParameters("", x0, x0)
|
||||
|
||||
type MyStruct =
|
||||
struct
|
||||
val X : int
|
||||
val Y : int
|
||||
val Z : int
|
||||
new(x, y, z) = { X = x; Y = y; Z = z }
|
||||
end
|
||||
|
||||
let myStructure1 = new MyStruct(1, 2, 3)
|
||||
|
||||
|
||||
// Error Each argument of the primary constructor for a struct must be given a type,
|
||||
// for example 'type S(x1:int, x2: int) = ...'.
|
||||
// These arguments determine the fields of the struct
|
||||
|
||||
type MyStruct2 =
|
||||
struct
|
||||
[<DefaultValue>]
|
||||
val mutable X : int
|
||||
|
||||
[<DefaultValue>]
|
||||
val mutable Y : int
|
||||
|
||||
[<DefaultValue>]
|
||||
val mutable Z : int
|
||||
end
|
||||
|
||||
let myStructure2 = new MyStruct2()
|
||||
|
||||
|
||||
|
||||
type MyClass3 =
|
||||
val a : int
|
||||
val b : int
|
||||
// The following version of the constructor is an error
|
||||
// because b is not initialized.
|
||||
// new (a0, b0) = { a = a0; }
|
||||
// The following version is acceptable because all fields are initialized.
|
||||
new(a0, b0) = { a = a0; b = b0; }
|
||||
|
||||
|
||||
type MyClass3_1 (a0, b0)=
|
||||
let a : int = a0
|
||||
let b : int = b0
|
||||
//val c : int
|
||||
|
||||
type MyClass3_2 =
|
||||
val a : int
|
||||
member this.b : int = 19
|
||||
|
||||
type MyClass3_3() =
|
||||
[<DefaultValue>] val mutable internal a : int
|
||||
[<DefaultValue>] val mutable b : int
|
||||
|
||||
type MyClass3_4 (a0, b0) =
|
||||
[<DefaultValue>] val mutable a : int
|
||||
[<DefaultValue>] val mutable b : int
|
||||
|
||||
let myClassObj = new MyClass3(35, 22)
|
||||
printfn "%d %d" (myClassObj.a) (myClassObj.b)
|
||||
|
||||
// type MyStruct3 (a0, b0) =
|
||||
// Each argument of the primary constructor for a struct must be given a type,
|
||||
// for example 'type S(x1:int, x2: int) = ...'.
|
||||
// These arguments determine the fields of the struct
|
||||
type MyStruct33 (a0:int, b0:int) =
|
||||
struct
|
||||
[<DefaultValue>] val mutable a : int
|
||||
[<DefaultValue>] val mutable b : int
|
||||
|
||||
new (a0:int) = MyStruct33(a0, 0)
|
||||
new (a0:int, b0:int, c0:int) = MyStruct33(a0, b0)
|
||||
end
|
||||
|
||||
let myStruct = new MyStruct33()
|
||||
let myStruct2 = new MyStruct33(10, 15)
|
||||
|
||||
type MyStruct44 (a0:int, b0:int) =
|
||||
struct
|
||||
[<DefaultValue>] val mutable a : int
|
||||
[<DefaultValue>] val mutable b : int
|
||||
end
|
||||
|
||||
|
||||
type MyStruct55 (a0:int, b0:int) =
|
||||
struct
|
||||
[<DefaultValue>] val mutable a : int
|
||||
[<DefaultValue>] val mutable b : int
|
||||
new (a0:int) = MyStruct55(34, 12) //then {this.a = 71}
|
||||
end
|
||||
|
||||
type MyStruct66 =
|
||||
struct
|
||||
val a : int
|
||||
val b : int
|
||||
new (a0:int) = {a = a0; b = 83}
|
||||
end
|
||||
|
||||
type MyStruct77 =
|
||||
struct
|
||||
[<DefaultValue>] val mutable a : int
|
||||
val b : int
|
||||
// new (a0:int) = {b = 83; a = 12} // doesn't work
|
||||
new (a0:int) = {b = 83}
|
||||
end
|
||||
|
||||
type MyStruct88 =
|
||||
struct
|
||||
[<DefaultValue>] val mutable a : int
|
||||
val b : int
|
||||
// new (a0:int) = {b = 83; a = 12} // doesn't work
|
||||
new (a0:int) = {b = 83}
|
||||
new (a0:int, b0:int) = {b = 87}
|
||||
end
|
||||
|
||||
|
||||
|
||||
type PetData = {
|
||||
name : string
|
||||
age : int
|
||||
animal : string
|
||||
}
|
||||
|
||||
type Pet(name:string, age:int, animal:string) =
|
||||
let mutable age = age
|
||||
let mutable animal = animal
|
||||
|
||||
new (name:string) =
|
||||
Pet(name, 5, "dog")
|
||||
|
||||
new (data:PetData) =
|
||||
Pet(data.name, data.age, data.animal) then System.Console.WriteLine("Pet created from PetData")
|
||||
|
||||
|
||||
|
||||
type public MyType =
|
||||
val private myvar: int
|
||||
val private myvar2: string
|
||||
|
||||
new () =
|
||||
for i in 1 .. 10 do
|
||||
printfn "Before field assignments %i" i
|
||||
{ myvar = 1; myvar2 = "test" }
|
||||
then
|
||||
for i in 1 .. 10 do
|
||||
printfn "After field assignments %i" i
|
||||
|
||||
|
||||
|
||||
|
||||
//A primary constructor in a class can execute code in a do binding.
|
||||
// However, what if you have to execute code in an additional constructor, without a do binding?
|
||||
// To do this, you use the then keyword.
|
||||
|
||||
// Executing side effects in the primary constructor and
|
||||
// additional constructors.
|
||||
type Person(nameIn : string, idIn : int) =
|
||||
let mutable name = nameIn
|
||||
let mutable id = idIn
|
||||
do printfn "Created a person object."
|
||||
member this.Name with get() = name and set(v) = name <- v
|
||||
member this.ID with get() = id and set(v) = id <- v
|
||||
new() =
|
||||
Person("Invalid Name", -1)
|
||||
then
|
||||
printfn "Created an invalid person object."
|
||||
new(person : Person) =
|
||||
Person(person.Name, person.ID)
|
||||
then
|
||||
printfn "Created a copy of person object."
|
||||
|
||||
let person1 = new Person("Humberto Acevedo", 123458734)
|
||||
let person2 = new Person()
|
||||
let person3 = new Person(person1)
|
||||
|
||||
|
||||
|
||||
|
||||
// Self Identifiers in Constructors
|
||||
// In other members, you provide a name for the current
|
||||
// object in the definition of each member.
|
||||
// You can also put the self identifier on the first line of the class definition
|
||||
// by using the as keyword immediately following the constructor parameters.
|
||||
// The following example illustrates this syntax.+
|
||||
type MyClass1(x) as this =
|
||||
// This use of the self identifier produces a warning - avoid.
|
||||
let x1 = this.X
|
||||
// This use of the self identifier is acceptable.
|
||||
do printfn "Initializing object with X =%d" this.X
|
||||
member this.X = x
|
||||
|
||||
|
||||
|
||||
// In additional constructors, you can also define a self identifier
|
||||
// by putting the as clause right after the constructor parameters.
|
||||
// The following example illustrates this syntax.
|
||||
type MyClass2(x : int) =
|
||||
member this.X = x
|
||||
new() as this = MyClass2(0) then printfn "Initializing with X = %d" this.X
|
||||
|
||||
|
||||
|
||||
// Assigning Values to Properties at Initialization
|
||||
// You can assign values to the properties of a class object in the initialization code
|
||||
// by appending a list of assignments of the form property = value
|
||||
// to the argument list for a constructor. This is shown in the following code example.
|
||||
type Account() =
|
||||
let mutable balance = 0.0
|
||||
let mutable number = 0
|
||||
let mutable firstName = ""
|
||||
let mutable lastName = ""
|
||||
member this.AccountNumber
|
||||
with get() = number
|
||||
and set(value) = number <- value
|
||||
member this.FirstName
|
||||
with get() = firstName
|
||||
and set(value) = firstName <- value
|
||||
member this.LastName
|
||||
with get() = lastName
|
||||
and set(value) = lastName <- value
|
||||
member this.Balance
|
||||
with get() = balance
|
||||
and set(value) = balance <- value
|
||||
member this.Deposit(amount: float) = this.Balance <- this.Balance + amount
|
||||
member this.Withdraw(amount: float) = this.Balance <- this.Balance - amount
|
||||
|
||||
|
||||
let account1 = new Account(AccountNumber=8782108,
|
||||
FirstName="Darren", LastName="Parker",
|
||||
Balance=1543.33)
|
||||
|
||||
|
||||
|
||||
|
||||
// The following version of the previous code illustrates the combination
|
||||
// of ordinary arguments, optional arguments, and property settings in one constructor call.
|
||||
type Account2(accountNumber : int, ?first: string, ?last: string, ?bal : float) =
|
||||
let mutable balance = defaultArg bal 0.0
|
||||
let mutable number = accountNumber
|
||||
let mutable firstName = defaultArg first ""
|
||||
let mutable lastName = defaultArg last ""
|
||||
member this.AccountNumber
|
||||
with get() = number
|
||||
and set(value) = number <- value
|
||||
member this.FirstName
|
||||
with get() = firstName
|
||||
and set(value) = firstName <- value
|
||||
member this.LastName
|
||||
with get() = lastName
|
||||
and set(value) = lastName <- value
|
||||
member this.Balance
|
||||
with get() = balance
|
||||
and set(value) = balance <- value
|
||||
member this.Deposit(amount: float) = this.Balance <- this.Balance + amount
|
||||
member this.Withdraw(amount: float) = this.Balance <- this.Balance - amount
|
||||
|
||||
|
||||
let account2 = new Account2(8782108, bal = 543.33,
|
||||
FirstName="Raman", LastName="Iyer")
|
||||
|
||||
|
||||
|
||||
// Constructors and Inheritance
|
||||
type MyClassBase2(x: int) =
|
||||
let mutable z = x * x
|
||||
do for i in 1..z do printf "%d " i
|
||||
|
||||
|
||||
type MyClassDerived2(y: int) =
|
||||
inherit MyClassBase2(y * 2)
|
||||
do for i in 1..y do printf "%d " i
|
||||
|
||||
|
||||
// In the case of multiple constructors, the following code can be used.
|
||||
// The first line of the derived class constructors is the inherit clause,
|
||||
// and the fields appear as explicit fields that are declared with the val keyword.
|
||||
// For more information, see Explicit Fields: The val Keyword.+
|
||||
type BaseClass =
|
||||
val string1 : string
|
||||
new (str) = { string1 = str }
|
||||
new () = { string1 = "" }
|
||||
|
||||
type DerivedClass =
|
||||
inherit BaseClass
|
||||
|
||||
val string2 : string
|
||||
new (str1, str2) = { inherit BaseClass(str1); string2 = str2 }
|
||||
new (str2) = { inherit BaseClass(); string2 = str2 }
|
||||
|
||||
let obj1 = DerivedClass("A", "B")
|
||||
let obj2 = DerivedClass("A")
|
13
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Customers.fs
vendored
Normal file
13
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Customers.fs
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
module Customers
|
||||
|
||||
|
||||
// Another way of implementing interfaces is to use object expressions.
|
||||
type ICustomer =
|
||||
abstract Name : string
|
||||
abstract Age : int
|
||||
|
||||
let createCustomer name age =
|
||||
{ new ICustomer with
|
||||
member __.Name = name
|
||||
member __.Age = age }
|
||||
|
119
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Delegates.fs
vendored
Normal file
119
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Delegates.fs
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
module Delegates
|
||||
|
||||
// The following code shows the syntax for creating delegates that represent various methods in a class.
|
||||
// Depending on whether the method is a static method or an instance method,
|
||||
// and whether it has arguments in the tuple form or the curried form,
|
||||
// the syntax for declaring and assigning the delegate is a little different.
|
||||
|
||||
type Test1() =
|
||||
static member add(a : int, b : int) =
|
||||
a + b
|
||||
static member add2 (a : int) (b : int) =
|
||||
a + b
|
||||
|
||||
member x.Add(a : int, b : int) =
|
||||
a + b
|
||||
member x.Add2 (a : int) (b : int) =
|
||||
a + b
|
||||
|
||||
let replicate n c = String.replicate n (string c)
|
||||
|
||||
|
||||
// Delegate specifications must not be curried types.
|
||||
// Use 'typ * ... * typ -> typ' for multi-argument delegates,
|
||||
// and 'typ -> (typ -> typ)' for delegates returning function values.
|
||||
|
||||
type Delegate1 = delegate of (int * int) -> int// Delegate1 works with tuple arguments.
|
||||
type Delegate2 = delegate of int * int -> int // Delegate2 works with curried arguments.
|
||||
type Delegate3 = delegate of int * char -> string
|
||||
type Delegate4 = delegate of int -> (int -> char)
|
||||
type Delegate5 = delegate of int -> (int -> char -> string)
|
||||
type Delegate6 = delegate of (int -> float) -> char
|
||||
type Delegate7 = delegate of (int -> char -> string) -> float
|
||||
type Delegate8 = delegate of int -> char
|
||||
type Delegate9 = delegate of (int * int) -> char
|
||||
type Delegate10 = delegate of int * int -> char
|
||||
type Delegate11 = delegate of char -> unit
|
||||
type Delegate12 = delegate of unit -> char
|
||||
type Delegate13 = delegate of (int -> char -> string -> decimal) -> float
|
||||
|
||||
|
||||
let function1(i : int, i2 : int) = 1
|
||||
let function2(i : int) (ch : int) = 1
|
||||
let function3(i : int) (s : char) = ""
|
||||
let function4(i : int) (ch : int) = ' '
|
||||
let function5(i : int) (i2 : int) (ch : char) = ""
|
||||
let function6(intIntFunction : int -> float) = ' '
|
||||
let function7(intCharStringFunction : int -> char -> string) = 0.5
|
||||
let function8(i : int) = ' '
|
||||
let function9(i : (int * int)) = ' '
|
||||
let function10(i : int) (i2 : int) = ' '
|
||||
let function11(c : char) = ()
|
||||
let function12(c : unit) = ' '
|
||||
let function12_1() = ' '
|
||||
let function13(intCharStringDecimalFunction : int -> char -> string -> decimal) = 0.5
|
||||
|
||||
let delObject1 = new Delegate1(function1)
|
||||
let delObject2 = new Delegate2(function2)
|
||||
let delObject3 = new Delegate3(function3)
|
||||
let delObject4 = new Delegate4(function4)
|
||||
let delObject5 = new Delegate5(function5)
|
||||
let delObject6 = new Delegate6(function6)
|
||||
let delObject7 = new Delegate7(function7)
|
||||
let delObject8 = new Delegate8(function8)
|
||||
let delObject9 = new Delegate9(function9)
|
||||
let delObject10 = new Delegate10(function10)
|
||||
let delObject11 = new Delegate11(function11)
|
||||
let delObject12 = new Delegate12(function12)
|
||||
let delObject12_1 = new Delegate12(function12_1)
|
||||
let delObject13 = new Delegate13(function13)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let InvokeDelegate1 (dlg : Delegate1) (a : int) (b: int) =
|
||||
dlg.Invoke(a, b)
|
||||
let InvokeDelegate2 (dlg : Delegate2) (a : int) (b: int) =
|
||||
dlg.Invoke(a, b)
|
||||
|
||||
// For static methods, use the class name, the dot operator, and the
|
||||
// name of the static method.
|
||||
let del1 : Delegate1 = new Delegate1( Test1.add )
|
||||
let del2 : Delegate2 = new Delegate2( Test1.add2 )
|
||||
|
||||
let testObject = Test1()
|
||||
|
||||
// For instance methods, use the instance value name, the dot operator, and the instance method name.
|
||||
let del3 : Delegate1 = new Delegate1( testObject.Add )
|
||||
let del4 : Delegate2 = new Delegate2( testObject.Add2 )
|
||||
|
||||
for (a, b) in [ (100, 200); (10, 20) ] do
|
||||
printfn "%d + %d = %d" a b (InvokeDelegate1 del1 a b)
|
||||
printfn "%d + %d = %d" a b (InvokeDelegate2 del2 a b)
|
||||
printfn "%d + %d = %d" a b (InvokeDelegate1 del3 a b)
|
||||
printfn "%d + %d = %d" a b (InvokeDelegate2 del4 a b)
|
||||
|
||||
// The following code shows some of the different ways you can work with delegates.
|
||||
|
||||
|
||||
// An F# function value constructed from an unapplied let-bound function
|
||||
let function1_ = replicate
|
||||
|
||||
// A delegate object constructed from an F# function value
|
||||
let delObject = new Delegate3(function1_)
|
||||
|
||||
// An F# function value constructed from an unapplied .NET member
|
||||
let functionValue = delObject.Invoke
|
||||
|
||||
List.map (fun c -> functionValue(5,c)) ['a'; 'b'; 'c']
|
||||
|> List.iter (printfn "%s")
|
||||
|
||||
// Or if you want to get back the same curried signature
|
||||
let replicate' n c = delObject.Invoke(n,c)
|
||||
|
||||
// You can pass a lambda expression as an argument to a function expecting a compatible delegate type
|
||||
// System.Array.ConvertAll takes an array and a converter delegate that transforms an element from
|
||||
// one type to another according to a specified function.
|
||||
let stringArray = System.Array.ConvertAll([|'a';'b'|], fun c -> replicate' 3 c)
|
||||
printfn "%A" stringArray
|
18
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/DiscriminatedUnions.fs
vendored
Normal file
18
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/DiscriminatedUnions.fs
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
module DiscriminatedUnions
|
||||
|
||||
//The preceding code declares a discriminated union Shape,
|
||||
// which can have values of any of three cases: Rectangle, Circle, and Prism.
|
||||
// Each case has a different set of fields.
|
||||
type Shape =
|
||||
| Rectangle of width : float * length : float
|
||||
| Circle of radius : float
|
||||
| Prism of width : float * float * height : float
|
||||
|
||||
let rect = Rectangle(length = 1.3, width = 10.0)
|
||||
let circ = Circle (1.0)
|
||||
let prism = Prism(5., 2.0, height = 3.0)
|
||||
|
||||
|
||||
type SizeUnion = Small | Medium | Large // union
|
||||
type ColorEnum = Red=5 | Yellow=7 | Blue=9 // enum
|
||||
|
16
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/DoBindings.fs
vendored
Normal file
16
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/DoBindings.fs
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
module DoBindings
|
||||
|
||||
open System
|
||||
|
||||
type MyBindingType(a:int, b:int) as this =
|
||||
inherit Object()
|
||||
let x = 2*a
|
||||
let y = 2*b
|
||||
do printfn "Initializing object %d %d %d %d %d %d"
|
||||
a b x y (this.Prop1) (this.Prop2)
|
||||
static do printfn "Initializing MyBindingType."
|
||||
member this.Prop1 = 4*x
|
||||
member this.Prop2 = 4*y
|
||||
override this.ToString() = System.String.Format("{0} {1}", this.Prop1, this.Prop2)
|
||||
|
||||
let obj1 = new MyBindingType(1, 2)
|
10
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Enumerations.fs
vendored
Normal file
10
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Enumerations.fs
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
module Enumerations
|
||||
|
||||
// Declaration of an enumeration.
|
||||
type Color =
|
||||
| Red = 0
|
||||
| Green = 1
|
||||
| Blue = 2
|
||||
|
||||
// Use of an enumeration.
|
||||
let col1 : Color = Color.Red
|
31
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Extensions.fs
vendored
Normal file
31
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Extensions.fs
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
module Extensions
|
||||
|
||||
module MyModule1 =
|
||||
|
||||
// Define a type.
|
||||
type MyClass() =
|
||||
member this.F() = 100
|
||||
|
||||
// Define type extension.
|
||||
type MyClass with
|
||||
member this.G() = 200
|
||||
|
||||
module MyModule2 =
|
||||
let function1 (obj1: MyModule1.MyClass) =
|
||||
// Call an ordinary method.
|
||||
printfn "%d" (obj1.F())
|
||||
// Call the extension method.
|
||||
printfn "%d" (obj1.G())
|
||||
|
||||
// Define a new member method FromString on the type Int32.
|
||||
type System.Int32 with
|
||||
member this.FromString( s : string ) =
|
||||
System.Int32.Parse(s)
|
||||
|
||||
let testFromString str =
|
||||
let mutable i = 0
|
||||
// Use the extension method.
|
||||
i <- i.FromString(str)
|
||||
printfn "%d" i
|
||||
|
||||
testFromString "500"
|
10
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/FlexibleTypes.fs
vendored
Normal file
10
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/FlexibleTypes.fs
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
module FlexibleTypes
|
||||
|
||||
let iterate1 (f : unit -> seq<int>) =
|
||||
for e in f() do printfn "%d" e
|
||||
let iterate2 (f : unit -> #seq<int>) =
|
||||
for e in f() do printfn "%d" e
|
||||
let iterate3<'T when 'T :> seq<int>> (f : unit -> 'T) = ()
|
||||
let iterate4<'T when 'T :> Customers.ICustomer> (f : unit -> 'T) = ()
|
||||
|
||||
|
35
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Functions.fs
vendored
Normal file
35
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Functions.fs
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
module Functions
|
||||
|
||||
// You define functions by using the let keyword, or, if the function is recursive, the let rec keyword combination.+
|
||||
let rec fib n = if n < 2 then 1 else fib (n - 1) + fib (n - 2)
|
||||
|
||||
let rec public publicLet n = if n < 2 then 1 else fib (n - 1) + fib (n - 2)
|
||||
|
||||
// Functions in F# can be composed from other functions.
|
||||
// The composition of two functions function1 and function2 is another function that represents the application of function1 followed the application of function2:
|
||||
let function1 x = x + 1
|
||||
let function2 x2 = x2 * 2
|
||||
let function3 (x3) = x3 * 2
|
||||
let function4 x4 y4 = x4 + y4
|
||||
let function5 (x5, y5) = x5 + y5
|
||||
let function6 (x6, y6) = ()
|
||||
let function7 x7 (y7, z7) = ()
|
||||
let function8 x8 y8 z8 = ()
|
||||
let function9 (x9, y9) (z9, a9) = ()
|
||||
let function10<'a> (x, y) (z, a) = ()
|
||||
let function11<'a> (x, y, z) (a, b) = ()
|
||||
let function12<'a> x (a, b, c, d, e) = ()
|
||||
let function13<'a> (a:'a) = ()
|
||||
|
||||
let get_function x = x + 1
|
||||
|
||||
let h = function1 >> function2
|
||||
let result5 = h 100
|
||||
|
||||
//Pipelining enables function calls to be chained together as successive operations. Pipelining works as follows:
|
||||
let result = 100 |> function1 |> function2
|
||||
|
||||
type TestFunction() =
|
||||
member this.f13 : 'a -> unit = function13
|
||||
// member this.f13<'a> : 'a -> unit = function13 // Error FS0671 A property cannot have explicit type parameters. Consider using a method instead.
|
||||
|
28
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Generics.fs
vendored
Normal file
28
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/Generics.fs
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
module Generics
|
||||
|
||||
// In the following code example, makeList is generic,
|
||||
// even though neither it nor its parameters are explicitly declared as generic.
|
||||
let makeList a b = [a; b]
|
||||
|
||||
// You can also make a function generic by using the single quotation mark syntax
|
||||
// in a type annotation to indicate that a parameter type is a generic type parameter.
|
||||
// In the following code, function1 is generic because its parameters are declared in this manner, as type parameters.
|
||||
let function1 (x: 'a) (y: 'a) =
|
||||
printfn "%A %A" x y
|
||||
|
||||
// You can also make a function generic by explicitly
|
||||
// declaring its type parameters in angle brackets (<type-parameter>)
|
||||
let function2<'T> x y =
|
||||
printfn "%A, %A" x y
|
||||
|
||||
|
||||
type Map2<[<EqualityConditionalOn>]'Key,[<EqualityConditionalOn>][<ComparisonConditionalOn>]'Value when 'Key : comparison and 'Value : comparison> = class
|
||||
//member this.Item ('Key) : 'Value (requires comparison)
|
||||
// member Item : key:'Key -> 'Value with get
|
||||
member this.fffff : option<int> = None
|
||||
member this.l : list<int> = [ 1; 2; 3 ]
|
||||
member this.c : Choice<int, float> = Choice1Of2 0
|
||||
member this.c2 : Choice<int, float> = Choice2Of2 0.5
|
||||
member this.r : ref<int> = ref 0
|
||||
member this.s : seq<int> = seq { for i in 1 .. 10 do yield i * i }
|
||||
end
|
30
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/IndexedProperties.fs
vendored
Normal file
30
external/api-doc-tools/mdoc/mdoc.Test/mdoc.Test.FSharp/IndexedProperties.fs
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
module IndexedProperties
|
||||
|
||||
type NumberStrings() =
|
||||
let mutable ordinals = [| "one"; "two"; "three"; "four"; "five";
|
||||
"six"; "seven"; "eight"; "nine"; "ten" |]
|
||||
let mutable cardinals = [| "first"; "second"; "third"; "fourth";
|
||||
"fifth"; "sixth"; "seventh"; "eighth";
|
||||
"ninth"; "tenth" |]
|
||||
member this.Item
|
||||
with get(index) = ordinals.[index]
|
||||
and set index value = ordinals.[index] <- value
|
||||
member this.Ordinal
|
||||
with get(index) = ordinals.[index]
|
||||
and set index value = ordinals.[index] <- value
|
||||
member this.Cardinal
|
||||
with get(index) = cardinals.[index]
|
||||
and set index value = cardinals.[index] <- value
|
||||
|
||||
let nstrs = new NumberStrings()
|
||||
nstrs.[0] <- "ONE"
|
||||
for i in 0 .. 9 do
|
||||
printf "%s " (nstrs.[i])
|
||||
printfn ""
|
||||
|
||||
nstrs.Cardinal(5) <- "6th"
|
||||
|
||||
for i in 0 .. 9 do
|
||||
printf "%s " (nstrs.Ordinal(i))
|
||||
printf "%s " (nstrs.Cardinal(i))
|
||||
printfn ""
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user