You are previewing Learning F# Functional Data Structures and Algorithms.
O'Reilly logo
Learning F# Functional Data Structures and Algorithms

Book Description

Get started with F# and explore functional programming paradigm with data structures and algorithms

In Detail

F# is a multi-paradigm programming language that encompasses object-oriented, imperative, and functional programming language properties. The F# functional programming language enables developers to write simple code to solve complex problems.

Starting with the fundamental concepts of F# and functional programming, this book will walk you through basic problems, helping you to write functional and maintainable code. Using easy-to-understand examples, you will learn how to design data structures and algorithms in F# and apply these concepts in real-life projects. The book will cover built-in data structures and take you through enumerations and sequences. You will gain knowledge about stacks, graph-related algorithms, and implementations of binary trees. Next, you will understand the custom functional implementation of a queue, review sets and maps, and explore the implementation of a vector. Finally, you will find resources and references that will give you a comprehensive overview of F# ecosystem, helping you to go beyond the fundamentals.

What You Will Learn

  • Familiarize yourself with the functional programming nature of F# and explore its fundamentals

  • Utilize data structures available in F# and apply recursion and lazy evaluation

  • Gain insights into functional programming paradigms; dissect F# code and analyze code available in community projects

  • Build abstract data structures and utilize powerful optimization techniques such as memoization

  • Explore and test built-in F# bespoke data structures and algorithms

  • Become resourceful and learn how to easily reuse libraries contributed by the C# and F# community

  • Understand the trade-offs in selecting purely functional (persistent) over mutable data structures

  • Implement custom ADT (Abstract Data Type), and discover parallel programming and asynchrony within F#

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Learning F# Functional Data Structures and Algorithms
      1. Table of Contents
      2. Learning F# Functional Data Structures and Algorithms
      3. Credits
      4. Foreword
      5. Foreword
      6. Foreword
      7. About the Author
      8. Acknowledgments
      9. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      11. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      12. 1. Embrace the Truth
        1. Exploring the functional programming paradigm
        2. Thinking functional – why functional programming matters
        3. A historical primer of F#
        4. The Hello World example
        5. A brief F# language primer
        6. Syntactical similarities and differences
        7. Benefits of using F# over C#
        8. Summary
      13. 2. Now Lazily Get Over It, Again
        1. Setting up the IDE
        2. Your first F# project
        3. Talk is cheap, show me some code
        4. To understand recursion, you must understand recursion
        5. Memoization with Fibonacci
        6. Towers of Hanoi
        7. Sorting lazily
        8. F# 4.0 – new features
        9. Summary
      14. 3. What's in the Bag Anyway?
        1. Exploring data structures in F#
          1. Arrays
          2. Lists
          3. List comprehensions
          4. Sequences
          5. Tuples and records
          6. Option types
          7. Sets and maps
          8. Discriminated unions
          9. The active pattern
        2. F# implementation of sorting algorithms
        3. Algorithmic complexity and the Big-O notation
          1. The bubble sort
          2. Quicksort
          3. The merge sort
        4. Summary
      15. 4. Are We There Yet?
        1. Diving deep into enumerations and sequences
        2. Enumerating a CSV file
        3. Query expressions
        4. Creating sequences from collections
        5. Usage considerations for sequences
        6. Summary
      16. 5. Let's Stack Up
        1. Let's build a stack
        2. Stack with concurrency support
        3. Testing the stack
        4. Algorithm – parenthesis matching using stacks
        5. Summary
      17. 6. See the Forest for the Trees
        1. Tree as a data structure
        2. The binary search tree
        3. Navigating the tree
        4. Abstract syntax trees
        5. Summary
      18. 7. Jumping the Queue
        1. Let's make a functional queue
        2. The FSharpx.Collections library
          1. The MailboxProcessor class in F#
        3. Summary
      19. 8. Quick Boost with Graph
        1. Graphs
        2. Modeling graphs using F#
        3. The shortest path algorithm
        4. Finding the minimal path sum
        5. Summary
      20. 9. Sets, Maps, and Vectors of Indirections
        1. Sets and maps
        2. Vectors
        3. F# and the Intermediate Language
        4. Summary
      21. 10. Where to Go Next?
        1. References and further readings
        2. F# language resources
        3. Component design guidelines
        4. Functional programming guides
          1. F# for fun and profit
          2. Data science with F#
          3. Math and statistics programming with F#
          4. Machine learning with F#
        5. Books and interactive tutorials
          1. Try F#
            1. The F# programming wikibook
            2. The F# workshop
            3. The F# cheat sheet
        6. Video tutorials
        7. Community projects – development tools
        8. Community projects – functional programming
        9. Community projects – data science programming
        10. Community projects – the GPU execution
        11. General functional programming
        12. Academic resources
        13. Summary
      22. Index