From Simple IO to Monad Transformers
2/5
()
About this ebook
From Simple IO to Monad Transformers is written for you if you know some Haskell, have seen a description or example of Haskell’s monads, and are not yet comfortable with the concept. You are also expected to have enough math background
to understand that function composition makes up some kind of algebraic system.
This ebook’s objective is to help you develop an intuitive notion of monad that is accurate enough to be useful. You may have found this difficult to achieve because the concept is abstract and explanations are often aimed at the mathematically sophisticated. When they are not, they tend to be of the “See how to do this! Wasn’t that easy?” variety.
Neither approach works very well. What you need is help understanding how abstractions organize details. Contrary to popular opinion, we cannot create abstractions by ignoring details. What abstractions do is control the time and place for such thinking. Edsger Dijkstra once reacted to the top-down programming movement–which he helped start–by writing that he himself did not create programs purely from the top down. He merely organized them that way for clarity and correctness.
Here the author discusses monads by looking at them from both the outside in and the inside out. The focus is on building understanding. Functors and applicative types are omitted. Those concepts can be stepping stones on the way to understanding monads but they are unnecessary with shorter approach I have chosen to use.
In prioritizing clearer explanations over content the author has also omitted almost all of the monads included with Haskell. You will find plenty of documentation online for those. The monads the author has chosen to present will give you a mental model for making
sense of that documentation.
Most sections have one worked exercise. It is OK if you cannot work it. Just pausing to think about it will give you a better understanding than merely reading through an example would.
Version 1.2 has expanded material on the List and State monads as well as on monad transformers. A few small errors have also been corrected. See the books website at BonsaiReads.com for an errata list.
J Adrian Zimmer
I was raised in Nebraska but have lived in the eastern, southern, and midwestern U.S., Canada, Denmark, and Iran. Educated through a postdoc in mathematics, my publications include three books. I recently retired knowing more about computer science than mathematics.
Related to From Simple IO to Monad Transformers
Related ebooks
An Introduction to Functional Programming Through Lambda Calculus Rating: 0 out of 5 stars0 ratingsLearning Concurrent Programming in Scala Rating: 0 out of 5 stars0 ratingsAlgebra: Polynomials, Galois Theory and Applications Rating: 0 out of 5 stars0 ratingsHaskell Data Analysis Cookbook Rating: 3 out of 5 stars3/5Get Programming with Haskell Rating: 0 out of 5 stars0 ratingsFundamentals of the Theory of Operator Algebras. V1: Elementary Theory Rating: 0 out of 5 stars0 ratingsJulia Quick Syntax Reference: A Pocket Guide for Data Science Programming Rating: 0 out of 5 stars0 ratingsClassical and Modern Integration Theories Rating: 1 out of 5 stars1/5Haskell High Performance Programming Rating: 0 out of 5 stars0 ratingsHaskell Design Patterns Rating: 0 out of 5 stars0 ratingsCommon Lisp A Complete Guide Rating: 1 out of 5 stars1/5Mathematical Doodlings Rating: 0 out of 5 stars0 ratingsBeginning Haskell: A Project-Based Approach Rating: 0 out of 5 stars0 ratingsLisp Interpreter in Rust Rating: 1 out of 5 stars1/5Perl 6 Quick Syntax Reference: A Pocket Guide to the Language, the Core Modules, and the Community Rating: 0 out of 5 stars0 ratingsOperator Methods in Quantum Mechanics Rating: 0 out of 5 stars0 ratingsHaskell in Depth Rating: 0 out of 5 stars0 ratingsFreeBSD Mastery: Storage Essentials: IT Mastery, #4 Rating: 0 out of 5 stars0 ratingsPractical Rust Web Projects: Building Cloud and Web-Based Applications Rating: 0 out of 5 stars0 ratingsRadioastronomical Methods of Antenna Measurements Rating: 0 out of 5 stars0 ratingsThe Art of Multiprocessor Programming, Revised Reprint Rating: 4 out of 5 stars4/5Learn to Program with Assembly: Foundational Learning for New Programmers Rating: 0 out of 5 stars0 ratingsGreen's Functions and Condensed Matter Rating: 3 out of 5 stars3/5Pattern-Oriented Software Architecture, On Patterns and Pattern Languages Rating: 5 out of 5 stars5/5Learning ClojureScript Rating: 0 out of 5 stars0 ratingsCommon LISP: The Language Rating: 4 out of 5 stars4/5Finite Dimensional Vector Spaces. (AM-7), Volume 7 Rating: 4 out of 5 stars4/5Regex Quick Syntax Reference: Understanding and Using Regular Expressions Rating: 0 out of 5 stars0 ratingsProgramming Language Structures Rating: 0 out of 5 stars0 ratingsA Primer on Statistical Distributions Rating: 0 out of 5 stars0 ratings
Computers For You
Deep Search: How to Explore the Internet More Effectively Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 5 out of 5 stars5/5How to Create Cpn Numbers the Right way: A Step by Step Guide to Creating cpn Numbers Legally Rating: 4 out of 5 stars4/5Network+ Study Guide & Practice Exams Rating: 4 out of 5 stars4/5Procreate for Beginners: Introduction to Procreate for Drawing and Illustrating on the iPad Rating: 0 out of 5 stars0 ratingsThe ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 0 out of 5 stars0 ratings101 Awesome Builds: Minecraft® Secrets from the World's Greatest Crafters Rating: 4 out of 5 stars4/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Ultimate Guide to Mastering Command Blocks!: Minecraft Keys to Unlocking Secret Commands Rating: 5 out of 5 stars5/5AP Computer Science Principles Premium, 2024: 6 Practice Tests + Comprehensive Review + Online Practice Rating: 0 out of 5 stars0 ratingsCompTIA Security+ Practice Questions Rating: 2 out of 5 stars2/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5CompTIA IT Fundamentals (ITF+) Study Guide: Exam FC0-U61 Rating: 0 out of 5 stars0 ratingsChildhood Unplugged: Practical Advice to Get Kids Off Screens and Find Balance Rating: 0 out of 5 stars0 ratingsChatGPT Ultimate User Guide - How to Make Money Online Faster and More Precise Using AI Technology Rating: 0 out of 5 stars0 ratingsPractical Lock Picking: A Physical Penetration Tester's Training Guide Rating: 5 out of 5 stars5/5Elon Musk Rating: 4 out of 5 stars4/5Dark Aeon: Transhumanism and the War Against Humanity Rating: 5 out of 5 stars5/5The Professional Voiceover Handbook: Voiceover training, #1 Rating: 5 out of 5 stars5/5Master Builder Roblox: The Essential Guide Rating: 4 out of 5 stars4/5Hacking: Ultimate Beginner's Guide for Computer Hacking in 2018 and Beyond: Hacking in 2018, #1 Rating: 4 out of 5 stars4/5
Reviews for From Simple IO to Monad Transformers
1 rating0 reviews
Book preview
From Simple IO to Monad Transformers - J Adrian Zimmer
Title Page
Copyright Page
Annotated List of Keywords
Annotated List of Sections
Preface
I. Pure Versus Impure
Ia Scope Example
Ib Impure Code
II. Functional Programming and the Real World
IIa Decomposed Haskell Program
IIb Question
IIc Answer
III. Monads and the (>>=) Combinator
IIIa Question
IIIb Answer
IV. The return Function
IVa getInt
IVb ask
IVc return_or_recurs
IVd Question
IVe Answer
V. Mimicking Composition of Functions
Va Question
Vb Answer
VI. The do Block
VIa Scoping In do Block
VIb Java-like Scoping
VIc Equivalent Monadic Expression
VId Substitution 1
VIe Substitution 2
VIf Substitution 3
VIg Monadic Expression Equivalent to do Block
VIh Equivalence Step 1
VIj Equivalence Step 2
VIk Equivalence Step 3
VIl Equivalence Step 4
VIm Equivalence Step 5
VIn Question
VIo Answer
VII. The List Monad
VIIa Nested do Block Loop
VIIb Defining pairs I
VIIc Defining pairs II
VIId Defining pairs III
VIIe Question
VIIf Answer
VIIg Program Testing pairs
VIII. Introduction to Monad Transformers
VIIIa 'Hello World'
VIIIb 'Hello World' Using LisT
VIIIc A Bit About GHCI
VIIId GHCI Example
VIIIe Nonloop Example
VIIIf Question
VIIIg Answer
IX. Intro to the State Monad
IXa State Monad (>>=)
IXb Question
IXc Answer
X. More About the State Monad
Xa Deriving >> for the State monad
Xb Testing get and put
Xc Question
Xd Answer
XI. A StateT Example.
XIa Repeated next_coins
XIb Definition of recurs
XIc Definition of dispense
XId Question
XIe Answer
XII. Monads
XIIa Definition of Monad
XIIb Monadic Axioms
XIIc Question
XIId Answer
About the Author
From Simple IO to Monad Transformers
by J Adrian Zimmer
Reader discussion encouraged at this ebooklet's web page.
Published by Bonsai Reads and distributed by Amazon.
Cover Design: Jennifer Melot
Copyright 2014 by J Adrian Zimmer
All rights reserved. Permission to copy is granted to the purchaser for personal use provided purchaser takes reasonable steps to prohibit further copying by others.
This is version 1.2. See for differences between versions.
There are two tables of contents. One is an annotated list of sections. The other has a listing for every major code segment.
Annotated List of Keywords
monad
Establishing a mindset for understanding Haskell's monads is the purpose of this publication.
Haskell
Readers are expected to know how to write simple recursive programs in the Haskell programming language.
functional programming
Functional and imperative programming are compared.
IO
Some examples involve console IO in Haskell.
list monad
Haskell's
List
monad is described.
state monad
Haskell's
State
monad is described.
monad transformer
Examples of monad transformers are given.
small screen
This monograph has been formatted for paging readers on small or large screens. Many code examples are hard coded into their own pages. Haskell source code has been kept to short line lengths.
Annotated List of Sections
I. Pure Versus Impure
Mathematical functions versus side-effects in computer programs.
II. Functional Programming and the Real World
Haskell's way