liveBook · Manning

Command-line tool

As explained in F# in Action: A Revised Edition of Get Programming with F#

A console application is a program that interacts with users or other processes through a text-based terminal.

A command-line tool is a console application that reads from and writes to a terminal. In F#, it is a direct way to turn a small piece of working code into a runnable program: accept console input, call domain logic, and print a result. Console output can range from plain text to richer terminal displays with tables, charts, and progress bars. section 1.3

Create a basic F# console application with the .NET CLI, then run it with `dotnet run`. The generated project includes a project file and `Program.fs`; templates can also create other application types, such as web apps and class libraries. section 2.3.3

mkdir helloworld              #1
cd helloworld                 #2
dotnet new console -lang F#   #3

Start a new directory, scaffold an F# console project, and use the generated program as the executable entry point. section 2.3.3

A useful workflow begins in a script, where a function can be modeled and explored quickly, then moves that function into a console project. Put reusable logic in a module such as `Car`, add its file to the project, and let `Program.fs` connect console interaction to that logic. section 6.2.3

F# project organization matters when a tool grows beyond one file:

  • Include every F# source file in the project file so it is compiled and available to the application. section 6.2.3
  • Order files by dependency: earlier files cannot access files listed later. section 6.2.3
  • Place the coordinating file, typically `Program.fs`, last so it can access the modules it needs. section 6.2.3

From car logic to terminal output

Move a `drive` function into `Car.fs`, then call it from the program: `let remaining = Car.drive 2 8`. Printing `You have {remaining} gas left.` turns an explored function into a small executable tool while keeping the domain calculation separate from console-facing code. section 6.2.3

A console application can also serve as an integration boundary. An F# project can reference a C# class library, open its namespace, construct a C# object, and print values from it. This keeps the command-line program compatible with mixed-language .NET solutions. section 11.1.1

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Walks through creation, source-file inclusion, dependency ordering, execution, and a C# project reference; it does not detail argument parsing.
Examples
Uses Hello World scaffolding, a car-driving program that prints remaining gas, and an F# application consuming a C# Person class.
What it assumes
Teaches console-project creation from terminal commands while assuming existing F# functions are available to move from a script.
What you can do after
Build it from scratch as an F# console application, organize its files, run it, and reference a C# project.
How it connects
Connects scripts, modules, project files, the .NET CLI, C# class libraries, and .NET interoperability.

Also explained in

Compare how 3 books explain command-line tool →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.