How do Haskell developers use monads?

Slides:



Advertisements
Similar presentations
Configuration management
Advertisements

What is a Parser? A parser is a program that analyses a piece of text to determine its syntactic structure  3 means 23+4.
Using Cabal and the Hackage Package Database. Hackage Hackage is a database of Haskell packages (or modules) written by others and available for public.
The Relational Database Model
Ihr Logo Data Explorer - A data profiling tool. Your Logo Agenda  Introduction  Existing System  Limitations of Existing System  Proposed Solution.
Purpose of study A high-quality computing education equips pupils to use computational thinking and creativity to understand and change the world. Computing.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Investigation.
RELATIONAL FAULT TOLERANT INTERFACE TO HETEROGENEOUS DISTRIBUTED DATABASES Prof. Osama Abulnaja Afraa Khalifah
Generic Approaches to Model Validation Presented at Growth Model User’s Group August 10, 2005 David K. Walters.
1 CSC 221: Computer Programming I Fall 2004 Lists, data access, and searching  ArrayList class  ArrayList methods: add, get, size, remove  example:
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
© M. Winter COSC 4P41 – Functional Programming Programming with actions Why is I/O an issue? I/O is a kind of side-effect. Example: Suppose there.
Evaluating Python as an Introductory Programming Language A. Thomas and H.L. Liang UNISA.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
A Monadic-Memoized Solution for Left-Recursion Problem of Combinatory Parser Rahmatullah Hafiz Fall, 2005.
Consultative process for finalizing the Guidance Document to facilitate the implementation of the clearing-house mechanism regional and national nodes.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Interactive Programs: I/O and Monads Dr. Hyunyoung Lee.
1 Chapter 12 Configuration management This chapter is extracted from Sommerville’s slides. Text book chapter 29 1.
0 PROGRAMMING IN HASKELL Chapter 4 - Defining Functions.
CS223: Software Engineering Lecture 19: Unit Testing.
Chapter 9 Introduction to Arrays Fundamentals of Java.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
© M. Winter COSC 4P41 – Functional Programming Further Features of Haskell Records data Customer = Customer { customerID :: Int, customerName ::
Lecture 3 – MapReduce: Implementation CSE 490h – Introduction to Distributed Computing, Spring 2009 Except as otherwise noted, the content of this presentation.
Functional Programming
Certification of Reusable Software Artifacts
Functional Programming
What is a Parser? A parser is a program that analyses a piece of text to determine its syntactic structure  3 means 23+4.
Conditional Expressions
Coupling and Cohesion Rajni Bhalla.
Evolution of UML.
Data Virtualization Tutorial: Introduction to SQL Script
Programming with ANSI C ++
Achieving High Software Reliability
Software Packaging and Releasing
Data Structure Interview Question and Answers
Coupling and Cohesion 1.
PROGRAMMING IN HASKELL
Chapter 18 Maintaining Information Systems
Sequences and Iterators
ADVANTAGES OF SIMULATION
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
Learn To Fix Errors On Dell PC. We are a third-party service provider for Dell users in Nederland. Call us on Website:
Genomic Data Clustering on FPGAs for Compression
CASE STUDY BY: JESSICA PATRON.
Functional Programming with Java
Abstract Data Types (ADTs)
Constructive Computer Architecture: Lab Comments & RISCV
HCI – DESIGN RATIONALE 20 November 2018.
Presentation 王睿.
Chapter 6 Methods: A Deeper Look
PROGRAMMING IN HASKELL
Understanding the Three Basic Structures
PROGRAMMING IN HASKELL
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Chapter Two: Review of the Literature
PROGRAMMING IN HASKELL
Chapter8: Statement-Level Control Structures April 9, 2019
How to use hash tables to solve olympiad problems
IPC144 Introduction to Programming Using C Week 4 – Lesson 1
Java Statements B.Ramamurthy CS114A, CS504 4/23/2019 BR.
Programming Languages
Information Retrieval and Web Design
PROGRAMMING IN HASKELL
Chapter Two: Review of the Literature
Database Systems: Design, Implementation, and Management
OPeNDAP/Hyrax Interfaces
Bug Localization with Combination of Deep Learning and Information Retrieval A. N. Lam et al. International Conference on Program Comprehension 2017.
Monitoring and evaluation Part 1 Lecture 10. Appraisal Vs Evaluation  Appraisal is before an activity takes place  Evaluation after the activity has.
Chapter 1: Creating a Program.
Presentation transcript:

How do Haskell developers use monads? A preliminary assessment Ismael Figueroa ismael.figueroa@pucv.cl http://zeus.inf.ucv.cl/~ifigueroa http://zeus.inf.ucv.cl/~ifigueroa/doku.php/research/empirical-monads

This works aims to bridge this gap in empirical knowledge About this work Programming with monads is perhaps one of the defining characteristics of the Haskell language However, despite the prevalence of monads and their use in programming Haskell software… we are not aware of any empirical studies on how Haskell developers use monads in their software This works aims to bridge this gap in empirical knowledge According to our results, the State monad is by far the most used one

Monads in a nutshell

Monads come from Category Theory (Moggi, ‘91) Notions of Computation: a value of type A is different from a computation of type T A Monads provide a mechanism for reasoning about non-pure programs in the lambda calculus

Monads in Functional Programming (Wadler, ‘92) class Monad m where return :: a -> m a (>>=) m a -> (a -> m b) -> m b Wadler proposes the use of monads for practical functional programming with notions of computation. In Haskell this is reflected by the Monad typeclass

mtl: monad transformers library Haskell provides a standardized programming interface for monadic programming: the mtl library. Based on monad transformers (Liang+ ’96), a mechanism for modular composition of monads Each notion of computation is implemented in several modules, data types and typeclasses

mtl Identity Error List Continuations State Reader Writer RWS pure computations computations that may fail may yield multiple non-deterministic values can be suspended, passed around, and resumed mtl mutable access to a collection of values read-only access to a collection of values write-only access to a collection of values combines State, Reader, and Writer State Reader Writer RWS

Monads as a “Design Pattern” dequeue :: StateT Identity [Int] dequeue = do queue <- get put (tail queue) return (head queue)

Monads as a “Design Pattern” dequeue :: StateT Identity [Int] dequeue = do queue <- get put (tail queue) return (head queue) StateT transformer Identity “Monad Stack” do is a sequence of the monad >>= function

Monads as a “Design Pattern” ErrorT transformer dequeue :: ErrorT String (StateT Identity [Int]) dequeue = do queue <- get put (tail queue) return (head queue) StateT transformer Identity Code is uniform with respect to the monad stack in use, avoids code repetition and boilerplate

Monads as a “Design Pattern” dequeue :: ErrorT String (StateT Identity [Int]) dequeue = do queue <- get if null queue then throwError "Empty queue“ else do put (tail queue) return (head queue) ErrorT transformer StateT transformer Identity Code is uniform with respect to the monad stack in use, avoids code repetition and boilerplate

Research Questions RQ1: How many packages directly depend on the mtl library? What is their distribution with respect to package metadata? RQ2: What is the usage distribution of mtl’s monads in packages that directly import mtl? RQ3: What is the situation of alternative implementations to the mtl, and their usage on existing packages?

Methodology

Methodology / Processing Pipeline Part 1: Simpler, answers just RQ1 Part 2: Complex, answers RQ2 and RQ3

Methodology / Package Index hackage.haskell.org is the de-facto repository for open-source Haskell software A tar.gz file with the hierarchical structure of Hackage and the package metadata

Methodology / Package Index Each subfolder is a version Each package has a folder Each versión is described by a .cabal file

Methodology / .cabal files key/value metadata

Methodology / Initial Package Data Name Version Stability Categories Dependencies Modules provided Main modules, for executables Other info for further processing… This data is enough to answer RQ1 It only requires processing the .cabal files, which is simple with the Cabal API

Methodology / Package Archives Processing Full source code of the package This is quite a complex step! Custom analysis program, using haskell-src-exts Set of modules imported by the package modules

Methodology /Packages with monad usage Initial Package Data, plus: Set of imported modules Indicator flags, 0 or 1, for each module that is available in the mtl With this we can answer RQ2 and RQ3! But it is complex and costly, we need to download and analyse the source code of each package version

Results

Results / RQ1 How many packages directly depend on the mtl library? What is their distribution with respect to package metadata? mtl-packages by stability , threshold at 3% Stability distribution of relevant categories mtl-packages by category, threshold at 5% On the 11171 packages analysed, we found 2803 mtl-packages Some packages had several categories, after considering this multiplicity we got 3670 unique package/category entries

Results / RQ2 What is the usage distribution of mtl’s monads in packages that directly import mtl? 600+ packages import mtl but use no monad??? Most packages use between 0 and 3 monads, and only outliers use more than 6… The State monad is the most used one, followed by the Reader monad. The Trans typeclass, used to create monad Transformers is also widely used!!

Results / RQ3 What is the situation of alternative implementations to the mtl, and their usage on existing packages? We found 104 packages that do not import mtl, but use one module that matches the name of an mtl module 78 packages use an alternative implementation of mtl The remaining 26 appear to implement their own customized versión of the monads they use

ONLY THE “LATEST” VERSION Limitations ONLY THE “LATEST” VERSION 11171 packages ~3GB of data 436 packages with parsing errors 451231 provided modules

Summary / Conclusions packages analysed: 11171 mtl-packages: 2803 (3670 single category) alt-mtl packages: 78 (104 with custom impl) parsed modules: 451231 pkgs with parsing errors: 438 Around 25% of sampled packages import the mtl The State monad is the most used one The monad Transformers module is also widely used Around 1% of sampled packages use alternatives to mtl We would like to answer qualitative questions: What are developers actually doing with the monad transformer class? How and why are developers creating their own monads? How does the usage of monads evolve over time, versions? http://zeus.inf.ucv.cl/~ifigueroa/doku.php/research/empirical-monads