Perhaps Not The Answer You Were Expecting But You Asked For It (An Accidental Blook) Conor McBride October 23, 2019 2 Contents 1 Haskell Curiosities 7 1.1 What is () in Haskell, exactly? . 7 1.2 What does () mean in Haskell? . 8 1.3 Implement the function lines in Haskell . 9 1.4 Boolean Expression evaluation (subtle type error) . 9 1.5 Purely functional data structures for text editors . 10 1.6 What are some motivating examples for Cofree CoMonad in Haskell? . 12 1.7 Find indices of things in lists . 15 1.8 How do I extend this mergeWords function to any number of strings? . 15 1.9 Example of UndecidableInstances yielding nonterminating typecheck . 16 1.10 Why do 3 and x (which was assigned 3) have different inferred types in Haskell? . 17 1.11 Use case for rank-3 (or higher) polymorphism? . 18 1.12 Why don’t Haskell compilers facilitate deterministic memory management? . 19 1.13 How does ArrowLoop work? Also, mfix? . 19 1.14 What does ) mean in a type signature? . 20 1.15 Meaning of Double and Floating point? . 21 1.16 Haskell terminology: meaning of type vs. data type, are they synonyms? . 22 1.17 Can you formulate the Bubble sort as a monoid or semigroup? . 23 1.18 Is this a correctly implemented mergesort in Haskell? . 24 1.19 Haskell type system nuances (ambiguity) . 26 1.20 Understanding a case of Haskell Type Ambiguity . 27 1.21 Why does Haskell use ! instead of =?.......................... 27 1.22 Is it possible to make a type an instance of a class if its type parameters are in the wrong order? . 28 1.23 Functor type variables for Flip data type . 29 1.24 Why does product [] return 1? . 30 1.25 Minimum of Two Maybes . 30 1.26 Is the equivalent of Haskell’s Foldable and Traversable simply a sequence in Clojure? 31 1.27 How do you keep track of multiple properties of a string without traversing it multiple times? . 32 1.28 Checking whether a binary tree is a binary search tree . 33 1.29 Finding a leaf with value x in a binary tree . 33 1.30 Taking from a list until encountering a duplicate . 34 1.31 RankNTypes and PolyKinds (quantifier alternation issues) . 35 1.32 How to write this case expression with the view pattern syntax? . 36 1.33 Recursive Type Families . 36 1.34 Determine whether a value is a function in Haskell . 38 1.35 Automatic Functor Instance (not) . 38 1.36 How do I apply the first partial function that works in Haskell? . 39 1.37 ‘Zipping’ a plain list with a nested list . 39 1.38 Bunched accumulations . 41 1.39 Functor on Phantom Type . 42 3 4 CONTENTS 1.40 Creating an Interpreter (with store) in Haskell . 43 1.41 Existential type wrappers necessity . 45 1.42 Non-linear Patterns in Type-Level Functions . 46 1.43 Initial algebra for rose trees . 46 2 Pattern Matching 49 2.1 Algorithm for typechecking ML-like pattern matching? . 49 2.2 Haskell Pattern Matching . 50 2.3 Complex pattern matching . 51 2.4 How to return an element before I entered? . 52 2.5 Buzzard Bazooka Zoom . 52 2.6 Why ++ is not allowed in pattern matching? . 54 3 Recursion 55 3.1 What are paramorphisms? . 55 3.2 Why can you reverse list with foldl, but not with foldr in Haskell . 56 3.3 Can fold be used to create infinite lists? . 59 3.4 How do I give a Functor instance to a datatype built for general recursion schemes? 59 3.5 Are there (term-transforming) morphisms in Haskell? . 61 3.6 Is this Fibonacci sequence function recursive? . 62 3.7 Can someone explain this lazy Fibonacci solution? . 63 3.8 Monoidal folds on fixed points . 64 3.9 List Created Evaluating List Elements . 65 3.10 Functions of GADTs . 66 4 Applicative Functors 69 4.1 Where to find programming exercises for applicative functors? . 69 4.2 N-ary tree traversal . 71 4.2.1 First Attempt: Hard Work . 71 4.2.2 Second Attempt: Numbering and Threading . 72 4.2.3 Third Attempt: Type-Directed Numbering . 74 4.2.4 Eventually. 75 4.3 Partial application of functions and currying, how to make a better code instead of a lot of maps? . 76 4.4 Translating monad to applicative . 77 4.5 Applicatives compose, monads don’t . 78 4.6 Examples Separating Functor, Applicative and Monad . 79 4.7 Parsec: Applicatives vs Monads . 80 4.8 Refactoring do notation into applicative style . 81 4.9 Zip with default values instead of dropping values? . 82 4.10 sum3 with zipWith3 in Haskell . 82 4.11 What is the ’Const’ applicative functor useful for? . 83 4.12 Applicative instance for free monad . 83 4.13 Examples of a monad whose Applicative part can be better optimized than the Monad part . 84 4.14 How arbitrary is the “ap” implementation for monads? . 85 4.15 Applicative without a functor (for arrays) . 85 4.16 Does this simple Haskell function already have a well-known name? (strength) . 86 4.17 The Kids are all Right . 87 4.18 Why is((,) r) a Functor that is NOT an Applicative? . 87 4.19 Applicative Rewriting (for reader) . 88 4.20 Serialised Diagonalisation . 89 4.21 Applicative style for infix operators? . 89 4.22 Where is the Monoid in Applicative? . 89 CONTENTS 5 4.23 Applicatives from Monoids including min and max . 93 5 Monads 95 5.1 Why we use monadic functions a ! m b ......................... 95 5.2 Monads with Join instead of Bind . 96 5.3 Using return versus not using return in the list monad . 97 5.4 Example showing monads don’t compose . 98 5.5 The Pause monad . 98 5.6 Haskell monad return arbitrary data type . 100 5.7 Should I avoid using Monad fail? . 100 5.8 Why isn’t Kleisli an instance of Monoid? . 101 5.9 Monads at the prompt? . 102 5.10 Is this a case to use liftM? . 102 5.11 Zappy colists do not form a monad . 104 5.12 Haskell io-streams and forever produces no output to stdout . 104 6 Differential Calculus for Types 105 6.1 Find the preceding element of an element in list . 105 6.2 Splitting a List . 106 6.3 nub as a List Comprehension . 108 6.4 How to make a binary tree zipper an instance of Comonad? . 109 6.5 What’s the absurd function in Data.Void useful for? . 115 6.6 Writing cojoin or cobind for n-dimensional grids . 117 6.6.1 Cursors in Lists . 117 6.6.2 Composing Cursors, Transposing Cursors? . 118 6.6.3 Hancock’s Tensor Product . 120 6.6.4 InContext for Tensor Products . 121 6.6.5 Naperian Functors . 121 6.7 Zipper Comonads, Generically . 122 6.8 Traversable and zippers: necessity and sufficiency . ..
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages213 Page
-
File Size-