[Haskell-cafe] Proposal: New syntax for Haskell

Artyom Kazak yom at artyom.me
Tue Sep 10 22:01:49 CEST 2013


This might do for businesses, but clearly not adequate if we want
Haskell/Cucumber (ever) to be suitable for use in government.

Here I’d like to suggest a more rigorous approach, which hopefully will be
considered for implementation instead of the original proposal.


                             MODULE Data.List

                               1st proposal

To promote prosperity, creativity, entrepreneurship, and innovation by
providing convenient functions operating on lists, and for other purposes.

                    IN THE STANDARD LIBRARY OF HASKELL

                            September 10, 2013

Mr. KAZAK of Russia, Saint-Petersburg (for himself and Mr. GEHR, Mr.  
HAMBÜCHEN,
Mr. WIEGLEY, Mr. ZIMMERMAN, Mr. CHEPLYAKA, Mr. ROSS, Mr. SNOYMAN, Mr.  
NEGRI,
Mr. YANG and Mr. FUJIMURA) introduced the following module; which was
referred to the Café of Haskell.


                                 A MODULE

Be it approved by the General Public and Maintainers of `base` package,


SECTION ONE. SHORT TITLE; TABLE OF CONTENTS
===========================================

(a) Short Title - This Module may be cited as the ‘Data.List module’.

(b) Table of Contents - The table of contents of this Module is as follows:

Sec. 1. Short title; table of contents.

...


TITLE I - HISTORY AND BACKGROUND
--------------------------------

Sec. 101. Definitions.

Sec. 102. Action by Simon Peyton-Jones to protect Haskell users and
prevent success at all costs¹.

Sec. 103. Immunity for taking voluntary action against LANGUAGE pragmas
dedicated to theft of syntax.

Sec. 104. Immunity for taking voluntary action against libraries that
make heavy use of unsafePerformIO.

Sec. 105. Guidelines and study.

Sec. 106. Denying `base` maintainership to notorious Applicative => Monad
proposal supporters.


TITLE II — THE ‘FOLDL’ FUNCTION
-------------------------------

Sec. 201. Type of ‘foldl’.

Sec. 202. Specification of ‘foldl’.

Sec. 203. Implementation of ‘foldl’.


END OF TABLE OF CONTENTS
------------------------


                      TITLE I — HISTORY AND DEFINITIONS

                           SEC. 101. DEFINITIONS.

In this title:

(1) FUNCTION - The term ‘function’ has the meaning implied in the
Haskell 98 Report, even though it isn’t actually given there.

(2) LIST - The term ‘list’ means a datatype used to provide the means
of accessing data stored in it sequentially, starting with the first
element and moving to the next element without delay, i.e. in O(1) time.

(3) EMPTY LIST — The term ‘empty list’ denotes a list which does not
contain any data, explicitly or implicitly, and which restricts any of
the attempts to obtain its first element through the well-defined
mechanism of exceptions and compile-time pattern match failures.

(3) NON-EMPTY LIST - The term ‘non-empty list’ means a list which is
not an empty list.
                                      ...


                      TITLE II — THE ‘FOLDL’ FUNCTION

                         SEC. 201. TYPE OF ‘FOLDL’

For any types A and B, be they sum types, product types, a valid  
combination
of sum and/or product types; types defined in the Standard Library, defined
by users of Haskell or defined in one of the Imported Modules; resulting
 from execution of Template Haskell; from execution of a generator written  
in
another programming language, not excluding Haskell; or written by  
human(s):

   (a) function ‘foldl’ requires an argument which itself must be a  
function:

     (1) which requires an argument of type A and shall produce a function:

     (2) which requires an argument of type B and shall produce
         a value of type A.

   (b) and shall produce a function:

     (1) which requires an argument of type A and shall produce a function:

     (2) which requires an argument of type, which denotes the set of all
         lists, empty or non-empty, together with bottom and further
         abominations, which shall contain elements of type B, and shall
         produce a value of type A.


                      SEC. 202. SPECIFICATION OF ‘FOLDL’

Assuming the following:

   (a) the argument of ′foldl’ is denoted by ‘f’.

   (b) the argument of the produced function is denoted by ′acc’.

   (c) the argument of the function, produced by the produced function,
       is denoted by ‘l’.

Then it shall be held that:

   (a) ‘foldl’ must be using ‘f’ while processing the elements of ‘l’, and
       it may not use any other function, either supplied to it implicitly
       or explicitly, defined in Data.List module, other modules included
       into Standard Library, Hackage or any other collection of modules.

     (1) Other functions may be defined for internal use by ‘foldl’, but
         they shall not be used to replace ‘f’, as it is deemed highly  
unlikely
         that any of such defined functions are adequate replacements of ‘f’
         and do not attempt to invade any country through means of launching
         missiles.

   (b) ‘foldl’ must process ‘l’ as follows:

     (1) it shall not skip an element.

     (2) it shall process the elements in the sequential order enforced by
         structure of list datatype.

     (3) it shall process the first element.

     (4) it shall process the last element or never produce anything.

     (5) it shall not use any element twice or any higher number of times.

   (c) ‘foldl’ must not produce a function which would be capable of
       resorting to any of the abominations when processing ‘l’.

     (1) specifically, when an argument of type A is demanded, it is  
permitted
         to use ‘acc’. Any usage of ‘bottom’ is prohibited.


                     SEC 203. IMPLEMENTATION OF ‘FOLDL’

The behaviour of function produced by ‘foldl’ when given a valid argument
‘f’ is described in this section.

   (a) Base case: ‘foldl’ shall produce a function which shall produce a
       function which, when it has been determined through pattern-matching
       or ‘null’ function, provided in Standard Library, that the list ‘l’
       is empty, shall use provided to it ‘acc’ as its returned value,
       without any attempt of modifying it.

   (b) Recursive case: ‘foldl' shall produce a function which shall produce
       a function which, when it has been determined through  
pattern-matching
       or ‘null’ function, possibly using ‘not’ function, both provided in
       Standard Library, that the list ‘l’ is non-empty, shall:

     (1) represent it as a pair consisting of the first element of ‘l’ and
         the list containing all elements of ‘l’, necessarily excluding the
         first element, in order of their appearance in ′l’; for clarity,
         the first element of that pair may be denoted by ‘x’, and the other
         element — as ‘xs’.

     (2) apply the function, produced by ‘foldl’, to the result of applying
         the result of applying ‘f’ to ‘acc’ to ‘x’, and apply the produced
         function to ‘xs’.

     (3) return the produced value.


¹just kidding, sorry.

On Tue, 10 Sep 2013 16:41:38 +0400, Timon Gehr <timon.gehr at gmx.ch> wrote:

> The above hardly is an acceptable state of affairs. While I appreciate  
> the effort, clearly Cucumber is a rather limited tool and should be  
> replaced by something more sophisticated that actually delivers the  
> promises of conciseness and being easy to read.
>
> My first shot (this can probably be made even more concise and/or easier  
> to read):
>
> Feature: The Data.List module
>
> In order to be able to use lists more conveniently
> As a programmer
> I want a module that defines some common operations on lists
>
> Scenario: Defining the function 'foldl'
>    Given I want to define 'foldl'
>    Which whenever given a thing that whenever given a thing of some  
> first kind will give a thing that whenever given a thing of some second  
> kind will give a thing of the first kind again, will give something that  
> whenever given a thing of the first kind will give something that  
> whenever given a list containing things of the second kind will give  
> something of the first kind.
>    When the list is empty
>    Then the result better be the aforementioned thing of the first kind
>    Otherwise the list has a first thing in it and the remaining things  
> form a list again. Then we get the result by giving to 'foldl' the first  
> thing mentioned and to the result we give the result we get by giving  
> the first thing in the list to the thing we get by giving the thing of  
> the first kind to the thing we already gave to 'foldl' and then give to  
> what we get the list of remaining things.



More information about the Haskell-Cafe mailing list