Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

From Simple IO to Monad Transformers
From Simple IO to Monad Transformers
From Simple IO to Monad Transformers
Ebook146 pages35 minutes

From Simple IO to Monad Transformers

Rating: 2 out of 5 stars

2/5

()

Read preview

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.

LanguageEnglish
Release dateMay 31, 2014
ISBN9780990451501
From Simple IO to Monad Transformers
Author

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

Computers For You

View More

Related articles

Reviews for From Simple IO to Monad Transformers

Rating: 2 out of 5 stars
2/5

1 rating0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    From Simple IO to Monad Transformers - J Adrian Zimmer

    cover.jpg

    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

    Enjoying the preview?
    Page 1 of 1