Magical Haskell: A Friendly Approach to Modern Functional Programming, Type Theory, and Artificial Intelligence

Оглавление⌄
About the Author ................................................................................................xiAbout the Technical Reviewer ...............................................................................xiiiAcknowledgments ...............................................................................................xvIntroduction .......................................................................................................xviiHow This Book Came to Be: Instead of an Introduction ............................................xixChapter 1: Wizards, Types, and Functions ....1Solving Problems As Wizards Do ....3Let’s Fall in Love with Types! ....7A Char and an Int Walk into a Bar and Make a Function ....8How FunTypical! ....12Curry and Recurse! ....15Conclusion ....19Chapter 2: Type Construction ....21House of Cards with a Little Help from Algebra ....22Algebraic Data Types ....25Records ....27Type Functions Are Functions, Maybe? ....30Advanced: On Data Constructors and Types ....37List, Recursion on Types and Patterns ....39Length of a List ....42Map a Function Over a List of Values ....44Conclusion ....50Chapter 3: Very Gentle Type Theory and Category Theory Intro ....51Types and Functions ....52Maybe and Advanced Generalized Functions ....54Dependent Function Types (Pi-Types) ....59Sum, Product, and Dependent Pair (Sigma) Types ....61Very Gentle Category Theory Introduction ....63Typeclasses ....66Conclusion ....70Chapter 4: Basic Typeclasses or “Show Me a Monoid” ....71Show Typeclass ....72Algebra Is Cool ....73Typeclass Hierarchy in Haskell ....76Lift Me Up! ....79Conclusion ....83Chapter 5: Functor, Bifunctor, and Applicative Functor Enteran Elevator … ....85Functor Typeclass Definition ....86Three-Dimensional Vector Example ....89Tracking Players in Our Game ....91You Are Either Functor or a Bifunctor ....92We Need a Bigger Lift ....98Action! Apply! Cut! ....104Applicative Typeclass ....107Conclusion ....111Chapter 6: O, Monad, Help Me Compose! ....113Can We Play Cards in This State? ....117Monad Typeclass and Basic Monads ....128Reader–Writer–State Triple ....132The State Monad ....132The Reader Monad ....135The Writer Monad ....140Conclusion ....145Chapter 7: Input, Transformer Stack, Output ....147Do Notation ....153Monad Transformer Stacks ....158Conclusion ....169Chapter 8: Blackjack: Full Haskell Program ....171Preparation ....174Initial “Pure” Design ....177Building the First Floor: IO ....183Building the Top Floor: StateT IO ....188Final Game and Recap ....197Conclusion ....201Chapter 9: Let’s AI ....203Agentic AI and Large Language Models ....203LLMs in a Nutshell ....205Haskell and LLMs ....210Big Picture of the Haskell AI Framework ....211Terminal Chatbot ....212Conclusion ....231Conclusion ....234Chapter 10: Terminal AI Chat Agent ....237Terminal UI Skeleton ....238Adding a Nicer Response Function ....239Initialization ....241Building the Monad Transformer Stack ....242Main Program ....245Building Muscles ....248Logging ....248Usage Stats in the Writer Monad ....253Chat History ....255Conclusion ....263Chapter 11: Web-Enabled AI Framework and GHC “Guts” ....265Terminal UI Improvements ....265Example Jarvis Scenarios ....270“M” Subchapter: Under the Hood of GHC ....278Adding a Web API ....283Mutable Variables ....294IORef: Simple Mutable Variables in the IO Monad ....295MVar: Mutable Variables with Concurrency Control ....296TVar: The Power of Software Transactional Memory (STM) ....298Conclusion ....300Chapter 12: Down the Rabbit Hole ....303MongoDB as a Persistence Layer ....304MongoDB Initialization ....308Adding a System Prompts Collection ....310Redesigning Architecture: MRWST Monad Transformer ....313Vectors and Type Families ....321Type Synonym Families ....322Data Families ....323Associated Type and Data Families ....325Vectors As Arrays in Haskell ....330More AI: Vector RAG ....340In-Memory Vector Engine ....344Conclusion ....358Chapter 13: AI Multi-agents, Arrows, and the Future ....359Arrows: The Last Abstraction ....361Arrows Definition and Basic Examples ....364Arrows Interface ....367AI Multi-agents and Arrows ....373AI Multi-agents Examples ....377Arrows to Support Quick AI Multi-agent Creation ....379Final Improvements for the AI Framework ....390Web Authentication with JWTs ....390Error Handling: Embracing the Try–Catch Approach ....396Multiple LLMs and Agents Support ....399Conclusion ....404Index ....407
Описание
В этом материале разберём тему: haskell.
This book uses playful metaphors and examples to help you learn Haskell through imagination, building on math without relying on imperative crutches or technical complexity. Discover a unique and fun approach to adopting modern typed functions programming patterns. You’ll use math to build completely different Typed Functional patterns from the ground up and understand the link between building Mathematics through Types and constructing Haskell as a programming language.
Illustrative explanations will guide you to tackle monads, using monad transformer stacks to structure real programs, foldable and traversable structures, as well as other Type classes. Intended for working with various applications, especially AI-powered apps, the book gently builds up to what are normally considered complex and difficult concepts all without needing a PhD to understand them. This book will also help you structure programs efficiently and apply your own abstractions to real-life problem domains. Finally, you’ll delve into AI multi-agents and future directions using Arrows abstraction, reinforcing Haskell’s design. Next, you’ll explore exciting advancements in AI, including building with OpenAI APIs, creating a terminal chatbot, adding web functionality, and enhancing with retrieval-augmented generation.
Magical Haskell is a solution for programmers who feel limited by imperative programming languages but are also put off by excessively mathematical approaches.
What You Will LearnGrasp a solid math foundation without complex technicalities for Types and Typeclasses.
Solve problems via a typed functional approach and understand why it’s superior to what’s available in the imperative language world (“if it compiles, it runs”).
Build your own abstractions to efficiently resolve problems in any given domain.
Develop AI frameworks in Haskell, including chatbots, web functionality, and retrieval-augmented generation.
Who This Book Is ForHaskell programmers of all levels and those interested in Type Theory.
На этом основные моменты по теме закрыты.
Поделиться
Частые вопросы
Можно ли скачать «Magical Haskell: A Friendly Approach to Modern Functional Programming, Type Theory, and Artificial Intelligence» бесплатно?
Да, «Magical Haskell: A Friendly Approach to Modern Functional Programming, Type Theory, and Artificial Intelligence» доступна для бесплатного скачивания на нашем сайте в формате PDF. Ссылка на файл находится на этой странице.
В каком формате и какого размера файл?
Книга предоставляется в формате PDF, размер файла 2,4 МБ.
Кто автор и когда вышла книга?
автор — Antich Anton, издательство Apress Media, LLC., год выпуска 2025, 428 страниц.
О чём книга «Magical Haskell: A Friendly Approach to Modern Functional Programming, Type Theory, and Artificial Intelligence»?
Discover a unique and fun approach to adopting modern typed functions programming patterns.