@@ -39,29 +39,33 @@ Fable.Python is a great choice when:
3939## When NOT to Use Fable.Python
4040
4141- When your F# code depends on .NET libraries without Fable support
42- - Performance-critical code (Python is still slow )
42+ - Performance-critical code (Python has runtime overhead )
4343- Team won't learn F#
4444
4545** Best fit:** You love F#, but need Python's ecosystem.
4646
47- ## A Simple Example
47+ ## A First Example
4848
49- Let's start with something simple. Here's F# code that will compile to Python:
49+ Let's start with F# code that compiles to Python:
5050*)
5151
5252let greet name = $" Hello, {name}!"
5353
5454let message = greet " Fable.Python"
5555
5656(**
57- When compiled with Fable, this generates clean, readable Python:
57+ When compiled with Fable, this generates the following Python:
58+ *)
5859
59- ``` python
60- def greet (name ):
61- return f " Hello, { name} ! "
60+ (* ** include-python: greet, message ***)
6261
63- message = greet(" Fable.Python" )
64- ```
62+ (**
63+ The ` name: Any | None = None ` signature may look odd at first. This happens because
64+ F# infers the type from usage - since we only call ` greet ` with a string, the compiler
65+ doesn't know if it might also be called with unit ` () ` (no argument). If it were,
66+ Python would call it as ` greet() ` instead of ` greet("Fable.Python") ` . Adding an
67+ explicit type annotation ` let greet (name: string) = ... ` would generate a cleaner
68+ ` name: str ` parameter.
6569
6670## The Power of Types
6771
@@ -82,9 +86,11 @@ let shapes = [ Circle 5.0; Rectangle(3.0, 4.0) ]
8286let totalArea = shapes |> List.sumBy area
8387
8488(**
85- This compiles to Python while preserving the semantic meaning. The discriminated
86- union becomes a tagged class structure, and pattern matching becomes clean
87- conditional logic.
89+ This compiles to Python while preserving the semantic meaning. The ` Shape ` type
90+ becomes a tagged class structure, and the ` match ` expression becomes clean
91+ conditional logic. The compiler ensures you handle all cases - if you add a
92+ new shape variant, the compiler will warn you about unhandled cases in
93+ the ` area ` function.
8894
8995## What's Next?
9096
@@ -94,5 +100,5 @@ In the following chapters, we'll cover:
94100- ** Bindings** - Working with Python libraries from F#
95101- ** Compatibility** - Understanding what F# features are supported
96102
97- Let's dive in!
103+ Let's begin.
98104*)
0 commit comments