Perhaps Not the Answer You Were Expecting but You Asked for It

Total Page:16

File Type:pdf, Size:1020Kb

Perhaps Not the Answer You Were Expecting but You Asked for It 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 . ..
Recommended publications
  • Haskell Communities and Activities Report
    Haskell Communities and Activities Report http://tinyurl.com/haskcar Thirty Fourth Edition — May 2018 Mihai Maruseac (ed.) Chris Allen Christopher Anand Moritz Angermann Francesco Ariis Heinrich Apfelmus Gershom Bazerman Doug Beardsley Jost Berthold Ingo Blechschmidt Sasa Bogicevic Emanuel Borsboom Jan Bracker Jeroen Bransen Joachim Breitner Rudy Braquehais Björn Buckwalter Erik de Castro Lopo Manuel M. T. Chakravarty Eitan Chatav Olaf Chitil Alberto Gómez Corona Nils Dallmeyer Tobias Dammers Kei Davis Dimitri DeFigueiredo Richard Eisenberg Maarten Faddegon Dennis Felsing Olle Fredriksson Phil Freeman Marc Fontaine PÁLI Gábor János Michał J. Gajda Ben Gamari Michael Georgoulopoulos Andrew Gill Mikhail Glushenkov Mark Grebe Gabor Greif Adam Gundry Jennifer Hackett Jurriaan Hage Martin Handley Bastiaan Heeren Sylvain Henry Joey Hess Kei Hibino Guillaume Hoffmann Graham Hutton Nicu Ionita Judah Jacobson Patrik Jansson Wanqiang Jiang Dzianis Kabanau Nikos Karagiannidis Anton Kholomiov Oleg Kiselyov Ivan Krišto Yasuaki Kudo Harendra Kumar Rob Leslie David Lettier Ben Lippmeier Andres Löh Rita Loogen Tim Matthews Simon Michael Andrey Mokhov Dino Morelli Damian Nadales Henrik Nilsson Wisnu Adi Nurcahyo Ulf Norell Ivan Perez Jens Petersen Sibi Prabakaran Bryan Richter Herbert Valerio Riedel Alexey Radkov Vaibhav Sagar Kareem Salah Michael Schröder Christian Höner zu Siederdissen Ben Sima Jeremy Singer Gideon Sireling Erik Sjöström Chris Smith Michael Snoyman David Sorokin Lennart Spitzner Yuriy Syrovetskiy Jonathan Thaler Henk-Jan van Tuyl Tillmann Vogt Michael Walker Li-yao Xia Kazu Yamamoto Yuji Yamamoto Brent Yorgey Christina Zeller Marco Zocca Preface This is the 34th edition of the Haskell Communities and Activities Report. This report has 148 entries, 5 more than in the previous edition.
    [Show full text]
  • Anders Åstrand: a Paragon of the Modern Musical Aesthetic
    University of Kentucky UKnowledge Theses and Dissertations--Music Music 2017 Anders Åstrand: A Paragon of the Modern Musical Aesthetic Matthew Geiger University of Kentucky, [email protected] Digital Object Identifier: https://doi.org/10.13023/ETD.2017.069 Right click to open a feedback form in a new tab to let us know how this document benefits ou.y Recommended Citation Geiger, Matthew, "Anders Åstrand: A Paragon of the Modern Musical Aesthetic" (2017). Theses and Dissertations--Music. 81. https://uknowledge.uky.edu/music_etds/81 This Doctoral Dissertation is brought to you for free and open access by the Music at UKnowledge. It has been accepted for inclusion in Theses and Dissertations--Music by an authorized administrator of UKnowledge. For more information, please contact [email protected]. STUDENT AGREEMENT: I represent that my thesis or dissertation and abstract are my original work. Proper attribution has been given to all outside sources. I understand that I am solely responsible for obtaining any needed copyright permissions. I have obtained needed written permission statement(s) from the owner(s) of each third-party copyrighted matter to be included in my work, allowing electronic distribution (if such use is not permitted by the fair use doctrine) which will be submitted to UKnowledge as Additional File. I hereby grant to The University of Kentucky and its agents the irrevocable, non-exclusive, and royalty-free license to archive and make accessible my work in whole or in part in all forms of media, now or hereafter known. I agree that the document mentioned above may be made available immediately for worldwide access unless an embargo applies.
    [Show full text]
  • STATICALLY CHECKING INTER-PROPERTY CONSTRAINTS and Its Applications in Web Apis
    Proefschrift ingediend met het oog op het behalen van een doctoraatsdiploma Dissertation submitted in fulfilment of the requirement for the degree of Doctor of Philosophy in Sciences STATICALLY CHECKING INTER-PROPERTY CONSTRAINTS and its Applications in Web APIs Nathalie Oostvogels Promotor: Prof. Dr. Wolfgang De Meuter Copromotor: Prof. Dr. Joeri De Koster Faculty of Science and Bio-Engineering Sciences Statically Checking Inter-property Constraints and its Applications in Web APIs Nathalie Oostvogels Dissertation submitted in fulfillment of the requirement for the degree of Doctor of Sciences April 2019 Jury: Prof. Dr. Wolfgang De Meuter, Vrije Universiteit Brussel (promotor) Prof. Dr. Joeri De Koster, Vrije Universiteit Brussel (copromotor) Prof. Dr. Ann Now´e,Vrije Universiteit Brussel (chair) Prof. Dr. Dominique Devriese, Vrije Universiteit Brussel (secretary) Prof. Dr. Ann Dooms, Vrije Universiteit Brussel Prof. Dr. Tobias Wrigstad, Uppsala University Dr. Manuel Serrano, INRIA Printed by: Crazy Copy Center Productions VUB Pleinlaan 2, 1050 Brussel Tel / fax : +32 2 629 33 44 [email protected] www.crazycopy.be ISBN 978 94 930 7921 2 NUR 989 Acknowledgements: The work in this dissertation has been funded by a PhD Fellowship of the Re- search Foundation - Flanders (FWO) and the SBO project Tearless by the Agency for Innovation and Entrepreneurship (VLAIO). Copyright: All rights reserved. No part of this publication may be produced in any form by print, photoprint, microfilm, electronic or any other means without permission from the author. c 2019 Nathalie Oostvogels Abstract Software applications do not stand on their own: their code often uses libraries to incorporate functionality to facilitate the development process (such as abstrac- tions and helper functions) or to integrate functionality from third parties.
    [Show full text]
  • A Bibliography of Publications in ACM SIGPLAN Notices, 2000–2009
    A Bibliography of Publications in ACM SIGPLAN Notices, 2000{2009 Nelson H. F. Beebe University of Utah Department of Mathematics, 110 LCB 155 S 1400 E RM 233 Salt Lake City, UT 84112-0090 USA Tel: +1 801 581 5254 FAX: +1 801 581 4148 E-mail: [email protected], [email protected], [email protected] (Internet) WWW URL: http://www.math.utah.edu/~beebe/ 09 November 2018 Version 1.82 Title word cross-reference '00 [2478, 33, 2480, 118, 119]. '01 [211]. 16-bit [855]. 2 [128, 1280]. 2000 [36, 327]. 2001 2 [1630]. 3 [1092, 1344, 1682, 1695, 248]. < [59, 58, 537, 274, 60]. 2003 [958, 1122]. 2008 [1230]. > [1230]. F [2067, 871]. TM [2060, 2005, 2164]. 21364 [674]. 21st [271]. [179, 175, 177]. ∆ [1505]. Γ [1615]. k [2088]. 28th [2482, 54]. λ [877, 960]. m [722]. N [1510, 2293, 522]. Π [1924, 2434]. Π0 [1630]. T [1364]. 6 [1715]. 64 [233, 364, 204]. -calculus [722, 960]. -complete [1630]. -pin '99 [16, 17]. [1344]. -queen [522]. -STL [27]. -synchronous [1510]. -valued [248]. -way = [534]. [2293]. abandoned [1032]. ABCD [90]. abduction .NET [1236, 2119, 1204, 865, 285, 973, 1348]. [2193]. Abstract [1190, 18, 985, 370, 926, 2292, 2362, 2365, /garbage [1919]. 1 2 2363, 2442, 499, 2366, 2367, 2295, 2358, 2075, 1108, 1402, 637, 893, 1281, 2048, 673, 770, 2443, 19, 1591, 500, 984, 2440, 2359, 408, 744, 839, 921, 2334, 2134, 340, 1077, 1572, 373]. 1582, 1946, 2297, 2360, 1826, 2446, 2400, 1615, adaptivity [1971]. Adding 253, 2441, 2199, 1192, 2364, 1211, 827, 1958, [1474, 1864, 1000, 2430, 1466].
    [Show full text]
  • Hermano José Marques Cintra.Pdf
    PONTIFÍCIA UNIVERSIDADE CATÓLICA DE SÃO PAULO PROGRAMA DE PÓS-GRADUAÇÃO EM TECNOLOGIAS DA INTELIGÊNCIA E DESIGN DIGITAL HERMANO JOSÉ MARQUES CINTRA A NOVA POTÊNCIA DA COOPERAÇÃO: efeitos da interatividade digital na ação coletiva empreendedora São Paulo - SP 2016 HERMANO JOSÉ MARQUES CINTRA A NOVA POTÊNCIA DA COOPERAÇÃO: efeitos da interatividade digital na ação coletiva empreendedora Tese apresentada à Banca Examinadora da Pontifícia Universidade Católica de São Paulo, exigência parcial para obtenção do título de Doutor em Tecnologias da Inteligência e Design Digital. Área de concentração: processos cognitivos e ambientes digitais Orientador: Profa. Dra. Maria Lucia Santaella Braga. São Paulo – SP 2016 ERRATA CINTRA, H J M. A Nova Potência da Cooperação: efeitos da interatividade digital na ação coletiva empreendedora. (Tese de Doutorado) Pontifícia Universidade Católica de São Paulo - Programa de Tecnologias da Inteligência e Design Digital, 2016. Folha (página) Linha Onde se lê: Leia-se: 19 (s/n) 4 <http://www.hcintra.com.br/linksdoutorado> <http://www.hcintra.com/linksdoutorado> 385 (355) 4 <http://www.hcintra.com.br/biBliodoutorado> <http://www.hcintra.com/biBliodoutorado> (Os endereços não possuem a terminação “.br”) Autorização de Publicação Autorizo a reprodução total ou parcial desta tese por processos de fotocópia ou eletrônicos para fins acadêmicos, científicos e educacionais, desde que citada a fonte. São Paulo, 28 de junho de 2016 Convite ao diáloGo O trabalho aqui apresentado procura entender a cooperação em ambiente digitais, portanto, não poderiam faltar meus localizadores digitais e meu convite à discussão dos temas abordados: Email: hcintra (em) hotmail.com Skype: hermano (ponto) cintra Site: www.hcintra.com Folha de Assinaturas da Banca Examinadora Profa.
    [Show full text]