Equational Reasoning for MTL Type Classes

07/01/2020
by   Härmel Nestra, et al.
0

Ability to use definitions occurring in the code directly in equational reasoning is one of the key strengths of functional programming. This is impossible in the case of Haskell type class methods unless a particular instance type is specified, since class methods can be defined differently for different instances. To allow uniform reasoning for all instances, many type classes in the Haskell library come along with laws (axioms), specified in comments, that all instances are expected to follow (albeit Haskell is unable to force it). For the type classes introduced in the Monad Transformer Library (MTL), such laws have not been specified; nevertheless, some sets of axioms have occurred in the literature and the Haskell mailing lists. This paper investigates sets of laws usable for equational reasoning about methods of the type classes MonadReader and MonadWriter and also reviews analogous earlier proposals for the classes MonadError and MonadState. For both MonadReader and MonadWriter, an equivalence result of two alternative axiomatizations in terms of different sets of operations is established. As a sideline, patterns in the choice of methods of different classes are noticed which may inspire new developments in MTL.

READ FULL TEXT
POST COMMENT

Comments

There are no comments yet.

Authors

page 1

page 2

page 3

page 4

08/17/2018

Proving Type Class Laws for Haskell

Type classes in Haskell are used to implement ad-hoc polymorphism, i.e. ...
07/17/2019

Defining Functions on Equivalence Classes

A quotient construction defines an abstract type from a concrete type, u...
06/28/2019

Bidirectional Type Class Instances (Extended Version)

GADTs were introduced in Haskell's eco-system more than a decade ago, bu...
07/23/2010

Uniform Approximation and Bracketing Properties of VC classes

We show that the sets in a family with finite VC dimension can be unifor...
01/02/2012

Technical Note: Exploring Σ^P_2 / Π^P_2-hardness for Argumentation Problems with fixed distance to tractable classes

We study the complexity of reasoning in abstracts argumentation framewor...
03/19/2018

Ready, Set, Verify! Applying hs-to-coq to real-world Haskell code

Good tools can bring mechanical verification to programs written in main...
12/14/2018

Graph classes and forbidden patterns on three vertices

This paper deals with graph classes characterization and recognition. A ...
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.