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 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 ratingsGet Programming with Haskell Rating: 0 out of 5 stars0 ratingsIntroducing Blockchain with Lisp: Implement and Extend Blockchains with the Racket Language Rating: 0 out of 5 stars0 ratingsHaskell High Performance Programming Rating: 0 out of 5 stars0 ratingsMathematical Doodlings Rating: 0 out of 5 stars0 ratingsBeginning Haskell: A Project-Based Approach Rating: 0 out of 5 stars0 ratingsProgramming Algorithms in Lisp: Writing Efficient Programs with Examples in ANSI Common Lisp Rating: 0 out of 5 stars0 ratingsInvitation to Combinatorial Topology Rating: 0 out of 5 stars0 ratingsHaskell in Depth Rating: 0 out of 5 stars0 ratingsLearning ClojureScript Rating: 0 out of 5 stars0 ratingsCommon Lisp A Complete Guide Rating: 1 out of 5 stars1/5Haskell Design Patterns Rating: 0 out of 5 stars0 ratingsC Clearly - Programming With C In Linux and On Raspberry Pi Rating: 0 out of 5 stars0 ratingsGreen's Functions and Condensed Matter Rating: 3 out of 5 stars3/5Objective-C Fundamentals Rating: 0 out of 5 stars0 ratingsRecursive Analysis Rating: 0 out of 5 stars0 ratingsFreeBSD Mastery: Advanced ZFS: IT Mastery, #9 Rating: 0 out of 5 stars0 ratingsGroup Theory: Birdtracks, Lie's, and Exceptional Groups Rating: 0 out of 5 stars0 ratingsBayesian Analysis of Stochastic Process Models Rating: 0 out of 5 stars0 ratingsIoT Projects with NVIDIA Jetson Nano: AI-Enabled Internet of Things Projects for Beginners Rating: 0 out of 5 stars0 ratingsEd Mastery (Manly McManface Edition) Rating: 0 out of 5 stars0 ratingsLisp (programming language) Complete Self-Assessment Guide Rating: 1 out of 5 stars1/5Introduction to Formal Languages Rating: 2 out of 5 stars2/5Communication Nets: Stochastic Message Flow and Delay Rating: 3 out of 5 stars3/5Water Waves: The Mathematical Theory with Applications Rating: 0 out of 5 stars0 ratingsTopics in Harmonic Analysis Related to the Littlewood-Paley Theory Rating: 0 out of 5 stars0 ratingsFreeBSD Mastery: Storage Essentials: IT Mastery, #4 Rating: 0 out of 5 stars0 ratingsA++ The Smallest Programming Language in the World: An Educational Programming Language Rating: 0 out of 5 stars0 ratings
Computers For You
The Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5Standard Deviations: Flawed Assumptions, Tortured Data, and Other Ways to Lie with Statistics Rating: 4 out of 5 stars4/5The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution Rating: 4 out of 5 stars4/5Slenderman: Online Obsession, Mental Illness, and the Violent Crime of Two Midwestern Girls Rating: 4 out of 5 stars4/5The Invisible Rainbow: A History of Electricity and Life Rating: 5 out of 5 stars5/5Elon Musk Rating: 4 out of 5 stars4/5The Professional Voiceover Handbook: Voiceover training, #1 Rating: 5 out of 5 stars5/5Procreate for Beginners: Introduction to Procreate for Drawing and Illustrating on the iPad Rating: 0 out of 5 stars0 ratingsUncanny Valley: A Memoir Rating: 4 out of 5 stars4/5101 Awesome Builds: Minecraft® Secrets from the World's Greatest Crafters Rating: 4 out of 5 stars4/5How to Create Cpn Numbers the Right way: A Step by Step Guide to Creating cpn Numbers Legally Rating: 4 out of 5 stars4/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 5 out of 5 stars5/5Ultimate Guide to Mastering Command Blocks!: Minecraft Keys to Unlocking Secret Commands 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/5Alan Turing: The Enigma: The Book That Inspired the Film The Imitation Game - Updated Edition Rating: 4 out of 5 stars4/5The ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 4 out of 5 stars4/5CompTIA Security+ Practice Questions Rating: 2 out of 5 stars2/5An Ultimate Guide to Kali Linux for Beginners Rating: 3 out of 5 stars3/5People Skills for Analytical Thinkers Rating: 5 out of 5 stars5/5Deep Search: How to Explore the Internet More Effectively 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/5Dark Aeon: Transhumanism and the War Against Humanity Rating: 5 out of 5 stars5/5What Video Games Have to Teach Us About Learning and Literacy. Second Edition 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