### Allowed Dependencies Graph Example Source: https://github.com/fable-compiler/fable/blob/main/src/fcs-fable/src/Compiler/Driver/GraphChecking/Docs.md Visualizes the allowed dependencies between F# files in a project, showing which files can influence others during type-checking. ```text A.fs -> [] B.fs -> [A.fs] C.fs -> [B.fs; A.fs] D.fs -> [C.fs; B.fs; A.fs] ``` -------------------------------- ### Local Installation of Fable-Compiler-JS Source: https://github.com/fable-compiler/fable/blob/main/src/fable-compiler-js/README.md Install Fable-Compiler-JS locally within a project using npm. Use `npx` to execute the `fable` command, ensuring project-specific versions are used. ```shell npm install fable-compiler-js ``` ```shell npx fable [--options] ``` -------------------------------- ### Module Abbreviations and Dependency Tracking Source: https://github.com/fable-compiler/fable/blob/main/src/fcs-fable/src/Compiler/Driver/GraphChecking/Docs.md This example demonstrates how module abbreviations are handled by the dependency tracking algorithm. Dependencies are tracked through indirect links, meaning no special handling is required for abbreviations themselves. ```fsharp // F1.fs module A module B = let x = 1 // F2.fs module C open A module D = B ``` -------------------------------- ### Global Installation of Fable-Compiler-JS Source: https://github.com/fable-compiler/fable/blob/main/src/fable-compiler-js/README.md Install Fable-Compiler-JS globally using npm for command-line access. This allows you to run the `fable` command from any directory. ```shell npm install -g fable-compiler-js ``` ```shell fable [--options] ``` -------------------------------- ### Python Union Pattern Matching Example Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Python/PYTHON-UNION.md Demonstrates how to use Python's `match` statement for pattern matching against union cases. It shows how to extract fields from different cases. ```python match u: case MyUnion_CaseA(item=value): print(f"CaseA: {value}") case MyUnion_CaseC(x_=x, y_=y): print(f"CaseC: {x}, {y}") ``` -------------------------------- ### Handling AutoOpen Modules in Dependency Graph Source: https://github.com/fable-compiler/fable/blob/main/src/fcs-fable/src/Compiler/Driver/GraphChecking/Docs.md This example illustrates how nested AutoOpen modules are handled. If a top-level module with AutoOpen is deemed potentially used, its contents, including nested AutoOpen modules, do not need further inspection. ```fsharp namespace A // If the algorithm determines module A.B is 'potentially used' in another file, there is no need to inspect its contents. module B = module C = // In particular there is no need to check this AutoOpen attribute [] module D = () ``` -------------------------------- ### Union Construction and Field Access Examples Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Python/PYTHON-UNION.md Demonstrates how to construct union instances directly using case classes and access their fields. Note that F# camelCase names are converted to snake_case with a trailing underscore in Python. ```python # Construction - use case classes directly u = MyUnion_CaseA(42) u = MyUnion_CaseC(1.0, 2.0) # Field access - direct attributes (camelCase F# names get a '_' suffix, see Case Field Naming) print(u.item) # For CaseA/CaseB print(u.x_, u.y_) # For CaseC ``` -------------------------------- ### Run Code Before Main with startup::on_startup! Source: https://github.com/fable-compiler/fable/blob/main/src/fable-library-rust/vendored/startup/README.md Use the `on_startup!` macro to define code that will execute before the `main` function. Be aware that not all standard library features might be available at this stage. ```rust startup::on_startup! { // Note: not all of the rust stdlib may be supported before main. println!("I'm running before main"); } fn main() { println!("I'm inside main"); } ``` -------------------------------- ### Show available build commands Source: https://github.com/fable-compiler/fable/blob/main/AGENTS.md Run this command to display all available build targets and options for the Fable project. ```bash ./build.sh ``` -------------------------------- ### Python Union Base Class cases() Method Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Python/PYTHON-UNION.md Demonstrates calling the `cases()` method on the base class of a union to get a list of its case names. ```python print(_MyUnion.cases()) # ["CaseA", "CaseB", "CaseC"] ``` -------------------------------- ### Python Type Annotated Union Function Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Python/PYTHON-UNION.md Provides an example of a Python function that uses type annotations with a union type alias and pattern matching for different cases. ```python def process(value: MyUnion) -> str: match value: case MyUnion_CaseA(item=i): return f"int: {i}" case MyUnion_CaseB(item=s): return f"str: {s}" case MyUnion_CaseC(x=x, y=y): return f"point: ({x}, {y})" def create() -> MyUnion: return MyUnion_CaseA(42) ``` -------------------------------- ### Testing Fable BEAM Backend - Phase 1 Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Beam/FABLE-BEAM.md This command demonstrates how to build and run the Fable CLI to test the BEAM backend with a simple Fable project. It compiles Fable code to Erlang and specifies output and caching options. ```bash dotnet build src/Fable.Cli dotnet run --project src/Fable.Cli --no-launch-profile -- \ --cwd src/quicktest-beam src/quicktest-beam/quicktest.fsproj \ --lang beam --outDir /tmp/beam-out --noCache ``` -------------------------------- ### Fable Supervision - Option C: Direct OTP Interop Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Beam/FABLE-BEAM.md Shows how to directly import and use OTP functions like `gen_server:start_link` within Fable code using Fable.Core attributes. This enables fine-grained control over OTP interactions. ```fsharp [] let startLink: ... = nativeOnly ``` -------------------------------- ### Test Rebuilding Everything with Pyright Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Python/TYPE-ANNOTATIONS.md Use this command to test rebuilding the entire project including fable-library, fable.library.core, and tests when running Pyright. ```bash # Test rebuilding everything (fable-library + fable.library.core + tests) ./build.sh test python --force-fable-library ``` -------------------------------- ### F# Namespace with Unused Open Statement Source: https://github.com/fable-compiler/fable/blob/main/src/fcs-fable/src/Compiler/Driver/GraphChecking/Docs.md Demonstrates a scenario where a namespace 'X' is opened in 'Y.fs' but is not strictly necessary. This setup can lead to type-checking errors if not handled by 'ghost dependencies'. ```fsharp namespace X ``` ```fsharp namespace Y open X // This open statement is unnecessary, however it is valid F# code. ``` -------------------------------- ### Python Base Class Method Type Annotation Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Python/PYTHON-UNION.md Shows an example of a method within a private base class of a union, using the base class name for type annotation of `self`. ```python class _MyUnion(Union): def GetHashCode(self) -> int: x: _MyUnion = self # Use base class for self return safe_hash(x) ``` -------------------------------- ### Fable Compiler Pipeline Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Beam/FABLE-BEAM.md Illustrates the compilation pipeline for Fable.Beam, showing the transformation from F# source to Erlang source files. ```text F# Source ↓ FSharp2Fable (existing) Fable AST ↓ FableTransforms (existing) Fable AST (optimized) ↓ Fable2Beam (NEW) Erlang AST ↓ ErlangPrinter (NEW) .erl source files ``` -------------------------------- ### F# Module Definitions Source: https://github.com/fable-compiler/fable/blob/main/src/fcs-fable/src/Compiler/Driver/GraphChecking/Docs.md Example F# modules within shared namespaces. These modules do not contain type definitions themselves, which allows Fable to optimize the dependency graph by not linking namespaces directly to files. ```fsharp module Foo.Bar.A let a = 0 ``` ```fsharp module Foo.Bar.B let b = 1 ``` -------------------------------- ### F# Project File Order Source: https://github.com/fable-compiler/fable/blob/main/src/fcs-fable/src/Compiler/Driver/GraphChecking/Docs.md Illustrates the default order in which F# files are processed during compilation. ```fsharp A.fs B.fs C.fs D.fs ``` -------------------------------- ### Fable Supervision - Option A: Attributes Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Beam/FABLE-BEAM.md Demonstrates using F# attributes to define supervision strategies and child processes for OTP integration. This approach allows declarative definition of supervision trees. ```fsharp [] module MyApp = [] let counter = CounterAgent.start ``` -------------------------------- ### Compiler Pipeline Stages Source: https://github.com/fable-compiler/fable/blob/main/AGENTS.md Illustrates the transformation stages of the Fable compiler, from F# source code to target language output. ```text F# Source → FCS Parser → F# AST → FSharp2Fable → Fable AST → FableTransforms → Fable2Target → Target AST → Printer → Output ``` -------------------------------- ### Build and Test Commands Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Python/PYTHON-UNION.md Commands to generate the Python output from Fable and run the associated tests. ```bash # Generate output ./build.sh quicktest python # Check generated code cat src/quicktest-py/quicktest.py # Run tests ./build.sh test python ``` -------------------------------- ### Test Rebuilding with Incremental Build Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Python/TYPE-ANNOTATIONS.md This command tests rebuilding the project while skipping the fable-library rebuild, leveraging incremental build capabilities. ```bash # Test rebuilding, but skipping fable-library rebuild (thanks to incremental build) ./build.sh test python ``` -------------------------------- ### Check Fable-Library with Pyright Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Python/TYPE-ANNOTATIONS.md Run Pyright on the generated fable-library code located in the temp/fable-library-py directory. ```bash # Check fable-library uv run pyright temp/fable-library-py ``` -------------------------------- ### Fable BEAM: Wrap Every Operation for int32 Source: https://github.com/fable-compiler/fable/blob/main/src/Fable.Transforms/Beam/FABLE-BEAM.md Demonstrates wrapping integer operations at every step to ensure correctness. This approach is safe but potentially slower. ```erlang %% F#: let x = a + b * c X = fable_int32:add(A, fable_int32:mul(B, C)) ```