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 ratingsFunctional Programming in C++ Rating: 0 out of 5 stars0 ratingsObject-oriented Programming with Smalltalk Rating: 0 out of 5 stars0 ratingsEssential Algorithms: A Practical Approach to Computer Algorithms Rating: 5 out of 5 stars5/5Learning Concurrent Programming in Scala Rating: 0 out of 5 stars0 ratingsGet Programming with Haskell Rating: 0 out of 5 stars0 ratingsHaskell Data Analysis Cookbook Rating: 3 out of 5 stars3/5Julia Quick Syntax Reference: A Pocket Guide for Data Science Programming Rating: 0 out of 5 stars0 ratingsHaskell Design Patterns Rating: 0 out of 5 stars0 ratingsLisp Interpreter in Rust Rating: 1 out of 5 stars1/5Common Lisp A Complete Guide Rating: 1 out of 5 stars1/5Haskell in Depth Rating: 0 out of 5 stars0 ratingsHaskell High Performance Programming Rating: 0 out of 5 stars0 ratingsBeginning Haskell: A Project-Based Approach Rating: 0 out of 5 stars0 ratingsFreeBSD Mastery: Storage Essentials: IT Mastery, #4 Rating: 0 out of 5 stars0 ratingsGreen's Functions and Condensed Matter Rating: 3 out of 5 stars3/5Programming Algorithms in Lisp: Writing Efficient Programs with Examples in ANSI Common Lisp Rating: 0 out of 5 stars0 ratingsProgramming Language Structures Rating: 0 out of 5 stars0 ratingsLearning ClojureScript Rating: 0 out of 5 stars0 ratingsFinite Dimensional Vector Spaces. (AM-7), Volume 7 Rating: 4 out of 5 stars4/5Learn ClojureScript: Functional programming for the web Rating: 0 out of 5 stars0 ratingsObjective-C Fundamentals Rating: 0 out of 5 stars0 ratingsFundamentals of the Theory of Operator Algebras. V1: Elementary Theory Rating: 0 out of 5 stars0 ratingsGetting Started with LLVM Core Libraries Rating: 0 out of 5 stars0 ratingsNNG Reference Manual, Second Edition Rating: 0 out of 5 stars0 ratingsNumberama: Recreational Number Theory in the School System Rating: 0 out of 5 stars0 ratingsPerl 6 Quick Syntax Reference: A Pocket Guide to the Language, the Core Modules, and the Community Rating: 0 out of 5 stars0 ratingsGeneral Theory of C*-Algebras Rating: 0 out of 5 stars0 ratingsAutomata, Languages, and Machines Rating: 4 out of 5 stars4/5Introduction to Parallel Programming Rating: 0 out of 5 stars0 ratings
Computers For You
How to Create Cpn Numbers the Right way: A Step by Step Guide to Creating cpn Numbers Legally 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 ratingsSQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 5 out of 5 stars5/5Learning the Chess Openings Rating: 5 out of 5 stars5/5CompTIA Security+ Get Certified Get Ahead: SY0-701 Study Guide Rating: 5 out of 5 stars5/5The ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 0 out of 5 stars0 ratingsThe Designer's Web Handbook: What You Need to Know to Create for the Web Rating: 0 out of 5 stars0 ratingsPractical Lock Picking: A Physical Penetration Tester's Training Guide Rating: 5 out of 5 stars5/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5CompTIA IT Fundamentals (ITF+) Study Guide: Exam FC0-U61 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 ratingsDeep Search: How to Explore the Internet More Effectively Rating: 5 out of 5 stars5/5Remote/WebCam Notarization : Basic Understanding Rating: 3 out of 5 stars3/5People Skills for Analytical Thinkers Rating: 5 out of 5 stars5/5Slenderman: Online Obsession, Mental Illness, and the Violent Crime of Two Midwestern Girls Rating: 4 out of 5 stars4/5Elon Musk Rating: 4 out of 5 stars4/5The Ridiculously Simple Guide to Google Docs: A Practical Guide to Cloud-Based Word Processing Rating: 0 out of 5 stars0 ratingsUltimate Guide to Mastering Command Blocks!: Minecraft Keys to Unlocking Secret Commands Rating: 5 out of 5 stars5/5Master Builder Roblox: The Essential Guide Rating: 4 out of 5 stars4/5Web Designer's Idea Book, Volume 4: Inspiration from the Best Web Design Trends, Themes and Styles Rating: 4 out of 5 stars4/5CompTIA Security+ Practice Questions Rating: 2 out of 5 stars2/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