Skip to content

Commit d061964

Browse files
Completed all translation work, ready for PR
1 parent 960debb commit d061964

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

zh-cn/fsharp.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -545,17 +545,17 @@ module AsyncExample =
545545
546546
module NetCompatibilityExamples =
547547
548-
// F# can do almost everything C# can do, and it integrates
549-
// seamlessly with .NET or Mono libraries.
548+
// C#能干的活,F# 基本上都能做。同时,F# 还无缝集成了 .Net 或 Mono 的库
549+
// 译者注:Mono库(Mono Libraries)的含义不太确定
550550
551-
// ------- work with existing library functions -------
551+
// ------- 使用已有的库函数 -------
552552
553553
let (i1success, i1) = System.Int32.TryParse("123");
554554
if i1success then printfn "parsed as %i" i1 else printfn "parse failed"
555555
556-
// ------- Implement interfaces on the fly! -------
556+
// ------- 简简单单实现接口(interface) -------
557557
558-
// create a new object that implements IDisposable
558+
// 创建一个实现了 IDisposable 的对象
559559
let makeResource name =
560560
{ new System.IDisposable
561561
with member this.Dispose() = printfn "%s disposed" name }
@@ -571,48 +571,47 @@ module NetCompatibilityExamples =
571571
printfn "using second resource"
572572
printfn "done."
573573
574-
// ------- Object oriented code -------
574+
// ------- 面向对象编程 -------
575575
576-
// F# is also a fully fledged OO language.
577-
// It supports classes, inheritance, virtual methods, etc.
576+
// F# 对面向对象编程的支持也很成熟,支持类、接口、虚函数等
578577
579-
// interface with generic type
578+
// 带有泛型的接口
580579
type IEnumerator<'a> =
581580
abstract member Current : 'a
582581
abstract MoveNext : unit -> bool
583582
584-
// abstract base class with virtual methods
583+
// 带有虚函数的抽象基类
585584
[<AbstractClass>]
586585
type Shape() =
587-
// readonly properties
586+
// 只读的成员变量
588587
abstract member Width : int with get
589588
abstract member Height : int with get
590-
// non-virtual method
589+
// 非虚函数
591590
member this.BoundingArea = this.Height * this.Width
592-
// virtual method with base implementation
591+
// 虚函数,且带有默认实现
593592
abstract member Print : unit -> unit
594593
default this.Print () = printfn "I'm a shape"
595594
596-
// concrete class that inherits from base class and overrides
595+
// 具象子类,继承上述抽象基类,并覆写(override)了其中的函数
597596
type Rectangle(x:int, y:int) =
598597
inherit Shape()
599598
override this.Width = x
600599
override this.Height = y
601600
override this.Print () = printfn "I'm a Rectangle"
602601
603-
// test
602+
// 试试看吧!
604603
let r = Rectangle(2, 3)
605604
printfn "The width is %i" r.Width
606605
printfn "The area is %i" r.BoundingArea
607606
r.Print()
608607
609-
// ------- extension methods -------
608+
// ------- 扩展已有类的方法 -------
610609
611-
// Just as in C#, F# can extend existing classes with extension methods.
610+
// 与 C# 一样,F# 也可以使用扩展语法来扩展已有类的方法
612611
type System.String with
613612
member this.StartsWithA = this.StartsWith "A"
614613
615-
// test
614+
// 试试看吧!
616615
let s = "Alice"
617616
printfn "'%s' starts with an 'A' = %A" s s.StartsWithA
618617

0 commit comments

Comments
 (0)