liveBook · Manning

Files

As explained in Functional Programming in Scala, Second Edition

Files is an algebraic data type representing primitive file-system operations supported by a free program.

Files is an algebraic data type for primitive file-system operations in a free program. Its operations describe file access without performing it immediately, keeping the program’s effects explicit and inspectable. section 13.5.1

A Files program can provide:

  • Different interpreters, including non-blocking, blocking, or pure state-based implementations. section 13.5.1
  • A precise effect boundary: Free[Files, A] can access the file system but not the console or network. section 13.5.1

Combining file and console effects

A cat utility reads lines with Files.readLines and prints them with Console.printLn. Because these belong to different algebras, the program must widen both operations into Free[[x] =>> Files[x] | Console[x], Unit] using union.

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Defines operations, interpreters, effect boundaries, and union-based composition, but defers interpreter implementations.
Examples
Uses ReadLines, WriteLines, and a cat utility that combines file reading with console output.
What it assumes
Assumes Free programs and Console effects while demonstrating file operations through an algebraic data type.
What you can do after
Build file programs as Free values and interpret them through blocking, non-blocking, or pure implementations.
How it connects
Connects algebraic data types, Free, interpreters, Console, and union types.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.