https://wiki.haskell.org/api.php?action=feedcontributions&user=Zzo38&feedformat=atomHaskellWiki - User contributions [en]2016-08-29T08:12:54ZUser contributionsMediaWiki 1.19.14+dfsg-1https://wiki.haskell.org/User:Zzo38/externUser:Zzo38/extern2012-02-22T21:10:27Z<p>Zzo38: Removing all content from page</p>
<hr />
<div></div>Zzo38https://wiki.haskell.org/User_talk:Zzo38/externUser talk:Zzo38/extern2012-02-22T21:09:47Z<p>Zzo38: New page: {{User:Zzo38/extern|hackage.haskell|.org|/packages/extensible-data|tr|extensible-data}}</p>
<hr />
<div>{{User:Zzo38/extern|hackage.haskell|.org|/packages/extensible-data|tr|extensible-data}}</div>Zzo38https://wiki.haskell.org/User:Zzo38/externUser:Zzo38/extern2012-02-22T21:07:50Z<p>Zzo38: New page: [h{{{4}}}p://{{{1}}}{{{2}}}{{{3}}} {{{5}}}]</p>
<hr />
<div>[h{{{4}}}p://{{{1}}}{{{2}}}{{{3}}} {{{5}}}]</div>Zzo38https://wiki.haskell.org/Extensible_recordExtensible record2012-02-22T21:03:40Z<p>Zzo38: </p>
<hr />
<div>__TOC__<br />
<br />
Proposals, implementations can be found on the [http://hackage.haskell.org/trac/haskell-prime/wiki/FirstClassLabels FirstClassLabels] page of Haskell' Wiki.<br />
<br />
== Papers and libraries ==<br />
* [http://homepages.cwi.nl/~ralf/HList/ HList --- a Haskell library for strongly typed heterogeneous collections] includes also extensible records. Its relatedness to database programming is described in the articles, see also its [http://hackage.haskell.org/trac/summer-of-code/ticket/33 possible] relatedness to [[Libraries and tools/Database interfaces/HaskellDB|HaskellDB]] project.<br />
* Daan Leijen: [http://www.cs.uu.nl/~daan/pubs.html#fclabels First-class labels for extensible rows]. See also the description of the Haskell-like language [http://www.cs.uu.nl/~daan/morrow/ Morrow], it is based on the concepts of the article. And [http://www.cs.uu.nl/~daan/pubs.html#scopedlabels Extensible records with scoped labels]: "We describe a natural approach to typing polymorphic and extensible records that is simple, easy to use in practice, and straightforward to implement."<br />
* Simon Peyton Jones and Greg Morrisett: [http://research.microsoft.com/~simonpj/Haskell/records.html A proposal for records in Haskell]<br />
* Mark Jones and Simon Peyton Jones: [http://research.microsoft.com/~simonpj/Papers/records.htm Lightweight Extensible Records for Haskell]<br />
* Mark P. Jones: [http://www.cs.sfu.ca/CourseCentral/SW/Haskell/hugs/TREX A prototype implementation of extensible records for Hugs]<br />
* Didier Remy's [http://www.cs.uu.nl/wiki/Uhc/ErikKnoop#Typing_record_concatenation_for Typing record concatenation for free] on Erik Knoop's page<br />
* Benedict R. Gaster, Mark P. Jones: [http://citeseer.ist.psu.edu/gaster96polymorphic.html A Polymorphic Type System for Extensible Records and Variants]<br />
* [http://www.comp.nus.edu.sg/~sulzmann/chameleon/ Chameleon], a Haskell-like language, see its [http://www.comp.nus.edu.sg/~sulzmann/chameleon/download/haskell.html#record records] [dead link as of 2011-09-15]<br />
* [[Grapefruit]] contains the package grapefruit-records which implements a record system in Haskell with GHC extensions. This record system allows field selection and dropping of fields using pattern matching. It also supports defaulting.<br />
* [http://www.informatik.tu-cottbus.de/~jeltsch/research/ppdp-2010-paper.pdf Generic Record Combinators with Static Type Checking] describes a record system with several novel features, which is provided by the [http://hackage.haskell.org/package/records records package]. It is derived from the record system of [[Grapefruit]].<br />
* The extensible-data package includes extensible records. <!-- sorry, the CAPTCHA is impossible to read. --><br />
<br />
== Applications ==<br />
<br />
=== Declarative database management ===<br />
<br />
Such systems can achieve more type safety (compared to direct SQL handling).<br />
They usually formulate a [[relational algebra]] concept in a declarative language.<br />
<br />
==== HaskellDB ====<br />
<br />
A problem where some concepts of extensible records could be useful is described in the [[Libraries and tools/Database interfaces/HaskellDB|HaskellDB]] project. More precisely, the problem is described in the paper downloadable from<br />
* [http://haskelldb.sourceforge.net/ Chalmers version of HaskellDB] (see ''Papers'' subsection on [http://haskelldb.sourceforge.net/#documentation Documentation])<br />
* which presupposes reading also paper on the [http://www.haskell.org/haskellDB/ Daan Leijen's original HaskellDB] page (see [http://www.haskell.org/haskellDB/doc.html Documentation subpage], PostScript version)<br />
<br />
[[Libraries and tools/Database interfaces/HaskellDB|HaskellDB]] uses its own extensible record system, but see also [[Libraries and tools/Database interfaces/HaskellDB#Future|HaskellDB#Future]].<br />
<br />
==== CoddFish ====<br />
<br />
[[Libraries and tools/Database interfaces/CoddFish|CoddFish]] is another declarative, type safe database system. As for extensible record system, it uses [http://homepages.cwi.nl/~ralf/HList/ HList --- a Haskell library for strongly typed heterogeneous collections].<br />
<br />
=== Functional Reactive Programming ===<br />
<br />
[[Functional Reactive Programming|FRP]] often makes it necessary to deal with very large tuples as arrow inputs and outputs. For example, a GUI component would receive the behavior of all its writeable properties as its input. Extensible records can therefore make FRP more usable, especially if they provide defaulting.<br />
<br />
==== Grapefruit ====<br />
<br />
[[Grapefruit]] uses extensible records which support pattern matching and defaulting for functional reactive GUI programming.<br />
<br />
== Related concepts ==<br />
<br />
[[Dependent type]] -- as an explanation for its relatedness here, see [http://www.dcs.st-andrews.ac.uk/~james/RESEARCH/ydtm-submitted.pdf Why Dependent Types Matter] written by Thorsten Altenkirch, Conor McBride, James McKinna -- or see at least its ''Conclusions'' section (section 8, pages 18--19).<br />
<br />
[[Type arithmetic]] seems to me also a way yielding some tastes from [[dependent type]] theory.<br />
<br />
[[Relational algebra]] implementations usually use extensible records.<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_additional_kindsUser:Zzo38/Proposal for additional kinds2012-01-12T20:18:10Z<p>Zzo38: </p>
<hr />
<div>This document is proposal about additional kinds.<br />
<br />
==New kinds==<br />
## -- New name for (#) kind (although (#) is available for compatibility)<br />
& -- Kind for classes<br />
+ -- Kind for type-level natural numbers<br />
$ -- Means make up a kind from a Template Haskell code<br />
<br />
==Kind of classes==<br />
Example:<br />
* -> & -- Kind of Eq class.<br />
(* -> *) -> & -- Kind of Monad class.<br />
(* -> &) -> & -- Class of classes.<br />
+ -> * -> & -- Infinite series of classes, selected by a natural number.<br />
<br />
==Natural number kind==<br />
If a type requires a parameter, it can be a <tt>+</tt> kind, meaning numbers.<br />
<br />
There should be some way to specify a type taking natural numbers by defining it for zero and them for a successor, so that it applies for all natural numbers.<br />
<br />
It also means a type of kind <tt>+ -> + -> +</tt> can be a type of adding numbers or other stuff like that, too.<br />
<br />
A natural number type would be a type with the number of values being that number, for example <tt>4</tt> is <tt>Maybe (Maybe (Maybe (Maybe Zero)))</tt>, and <tt>(-&gt;)</tt> would be the type for a array with a specific number of elements fixed by the type.<br />
<br />
==See also==<br />
* [http://hackage.haskell.org/trac/ghc/wiki/KindFact KindFact]<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_macrosUser:Zzo38/Proposal for macros2012-01-12T20:14:58Z<p>Zzo38: </p>
<hr />
<div>This document list proposal for use of macros in Haskell.<br />
<br />
=Defining macros=<br />
<br />
By convention the macros will start with underscore followed by an uppercase letter, but would not be enforced. Macro names can start with any lowercase letter.<br />
<br />
This document reuses the <tt>type</tt> keyword to define macros (if the name is not capitalized, it is a macro), but the implementation could be different.<br />
<br />
Macro parameters would be a token or a token block (such as in parentheses). Names would be normally hygienic.<br />
<br />
Partially applied macros (like partially applied type synonyms) are not allowed except with other macros.<br />
<br />
A macro might expand to an entire block of definitions, possibly with private names and include files, or to a single expression, or a type, or kind, etc.<br />
<br />
Possibly a macro expansion could even include Template Haskell codes, which themself could even expand to macros.<br />
<br />
Macros do not have to be referentially transparent, unlike functions. They could even count how many times it is used, to make a new unique name each time, like Template Haskell codes can also do.<br />
<br />
=Macros for catching pattern failure=<br />
<br />
Example:<br />
{-# LANGUAGE Macro #-}<br />
import Control.Exception.Macro;<br />
a :: Int -> Int -> Int;<br />
a 0 x = x;<br />
a 1 x = x + x;<br />
b :: Int -> Int -> Either String Int;<br />
b = _Catch 2 a;<br />
c :: Int -> Int -> IO Int;<br />
c = _CatchIO 2 a;<br />
d :: Int -> IO (Int -> Int);<br />
d = _CatchIO 1 a;<br />
e :: [String];<br />
e = ["hello", "world", undefined];<br />
f :: IO [String];<br />
f = _CatchStrictIO 0 e do {<br />
case _This of {<br />
[] <- _Stop;<br />
h : t <- do {<br />
h;<br />
_Again t;<br />
};<br />
};<br />
};<br />
<br />
Meanings:<br />
b 0 = Right;<br />
b 2 = const $ Left "pattern match error";<br />
c 0 = return;<br />
c 2 = const $ fail "pattern match error";<br />
d 0 = return id;<br />
f = fail "undefined";<br />
<br />
Note that <tt>_Catch</tt> and so on are macros, not functions. A macro is not a first-class value in the program, and cannot be used at run-time, but can have operations that a function doesn't have.<br />
<br />
When calling the new function created by the macro, errors are converted to the return value instead (a function could not read undefined values, but a macro could change it into a different function so that it is not undefined).<br />
<br />
You could specify strictifying with do-notation to ensure everything in there is defined before returning a value, so that an undefined value will be caught ahead of time.<br />
<br />
User errors and pattern match errors can be caught even in a pure code, but out of memory error can only be caught in I/O actions.<br />
<br />
=Macros for values with multiple types=<br />
<br />
Example:<br />
f x y = (either x x (y :: Either Int String)) :: Bool;<br />
<br />
What would be type of <tt>f</tt>? There is no type, because <tt>x</tt> must be something with two types, such as a class method.<br />
<br />
But you can make a macro:<br />
type f x y = either x x y;<br />
<br />
Which is allowed, it has no type. But you cannot partially apply it, since it is not a function.</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_macrosUser:Zzo38/Proposal for macros2012-01-12T20:01:05Z<p>Zzo38: </p>
<hr />
<div>This document list proposal for use of macros in Haskell.<br />
<br />
=Defining macros=<br />
<br />
=Macros for catching pattern failure=<br />
<br />
Example:<br />
{-# LANGUAGE Macro #-}<br />
import Control.Exception.Macro;<br />
a :: Int -> Int -> Int;<br />
a 0 x = x;<br />
a 1 x = x + x;<br />
b :: Int -> Int -> Either String Int;<br />
b = _Catch 2 a;<br />
c :: Int -> Int -> IO Int;<br />
c = _CatchIO 2 a;<br />
d :: Int -> IO (Int -> Int);<br />
d = _CatchIO 1 a;<br />
e :: [String];<br />
e = ["hello", "world", undefined];<br />
f :: IO [String];<br />
f = _CatchStrictIO 0 e do {<br />
case _This of {<br />
[] <- _Stop;<br />
h : t <- do {<br />
h;<br />
_Again t;<br />
};<br />
};<br />
};<br />
<br />
Meanings:<br />
b 0 = Right;<br />
b 2 = const $ Left "pattern match error";<br />
c 0 = return;<br />
c 2 = const $ fail "pattern match error";<br />
d 0 = return id;<br />
f = fail "undefined";<br />
<br />
Note that <tt>_Catch</tt> and so on are macros, not functions. A macro is not a first-class value in the program, and cannot be used at run-time, but can have operations that a function doesn't have.<br />
<br />
When calling the new function created by the macro, errors are converted to the return value instead (a function could not read undefined values, but a macro could change it into a different function so that it is not undefined).<br />
<br />
You could specify strictifying with do-notation to ensure everything in there is defined before returning a value, so that an undefined value will be caught ahead of time.<br />
<br />
User errors and pattern match errors can be caught even in a pure code, but out of memory error can only be caught in I/O actions.</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_macrosUser:Zzo38/Proposal for macros2012-01-12T19:53:37Z<p>Zzo38: New page: This document list proposal for use of macros in Haskell. =Defining macros= =Macros for catching pattern failure= Example: a :: Int -> Int -> Int; a 0 x = x; a 1 x = x + x; b :: Int...</p>
<hr />
<div>This document list proposal for use of macros in Haskell.<br />
<br />
=Defining macros=<br />
<br />
=Macros for catching pattern failure=<br />
<br />
Example:<br />
a :: Int -> Int -> Int;<br />
a 0 x = x;<br />
a 1 x = x + x;<br />
b :: Int -> Int -> Either String Int;<br />
b = _Catch 2 a;<br />
c :: Int -> Int -> IO Int;<br />
c = _CatchIO 2 a;<br />
d :: Int -> IO (Int -> Int);<br />
d = _CatchIO 1 a;<br />
e :: [String];<br />
e = ["hello", "world", undefined];<br />
f :: IO [String];<br />
f = _CatchStrictIO 0 e do {<br />
case _This of {<br />
[] <- _Stop;<br />
h : t <- do {<br />
h;<br />
_Again t;<br />
};<br />
};<br />
};<br />
<br />
Meanings:<br />
b 0 = Right;<br />
b 2 = const $ Left "pattern match error";<br />
c 0 = return;<br />
c 2 = const $ fail "pattern match error";<br />
d 0 = return id;<br />
f = fail "undefined";</div>Zzo38https://wiki.haskell.org/User:Zzo38User:Zzo382012-01-12T19:44:36Z<p>Zzo38: +Proposal for macros</p>
<hr />
<div>I am allowing all texts I typed into this wiki as public domain. The simple permissive license of Haskell Wiki is also permitted, so you can use that in case public domain is not possible.<br />
<br />
I have made one Haskell program so far:<br />
* [http://zzo38computer.cjb.net/prog/Constantinople.zip Constantinople compiler] (this program uses [[Parsec]] and [[Template Haskell]])<br />
<br />
Subpage:<br />
* [[User:Zzo38/Proposal for more-notation|Proposal for more-notation]]<br />
* [[User:Zzo38/Proposal about classes|Proposal about classes]]<br />
* [[User:Zzo38/Proposal for additional kinds|Proposal for additional kinds]]<br />
* [[User:Zzo38/Proposal for Haskell preprocessor|Proposal for Haskell preprocessor]]<br />
* [[User:Zzo38/Proposal for instance disambiguation|Proposal for instance disambiguation]]<br />
* [[User:Zzo38/Proposal for macros|Proposal for macros]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_instance_disambiguationUser:Zzo38/Proposal for instance disambiguation2011-12-20T02:20:32Z<p>Zzo38: </p>
<hr />
<div>This document has some of my ideas about instance disambiguations and related things how it could be implemented in Haskell. There may be some mistake, so it is good for other people complain what is wrong so that it can be corrected.<br />
<br />
=Select instances from imported modules=<br />
Example:<br />
import A () instance ();<br />
import B class (AAA as ZZZ qualified as HHH);<br />
import C hiding instance (Num String, Num Bool);<br />
import D type (T as TT, U as newtype UU);<br />
From module A imports nothing not even instances. From module B imports instances of class AAA to be instances of class ZZZ instead, where all its methods are prefixed with "HHH." at the front. From module C, does not import instances of Num class for type String (this is only valid if type synonym instances is enabled, and means the same thing here) and Bool. From module D, the type named T is named TT when imported, for all functions using it, all instances, etc. If T is a type from a different module, then all function and instance from D using type T will make a new type TT instead. Instances for the type U are instead for a new type UU which is U wrapped in a newtype.<br />
<br />
=Override instances=<br />
Example:<br />
import E hiding module C;<br />
This hides instances in C which conflict with those of E, and hides names (except qualified)<br />
<br />
Example:<br />
instance Num Int where {<br />
x + y = 42;<br />
};<br />
This, defined in a module, automatically overrides instances from imported modules.<br />
<br />
Example:<br />
instance (instance IsString [Char] hiding) => IsString [x];<br />
It means that this is instance for any list but if there is instance for strings, that one will override this one.<br />
<br />
Example:<br />
instance Num x => Monoid (x as newtype (Sum x)) where {<br />
mempty = 0;<br />
mappend = (+);<br />
};<br />
Allows you to define newtype as part of an instance declaration, doing wrapping and unwrapping automatically.<br />
<br />
=Instance with imported modules=<br />
In general, you override instance, it doesn't affect functions from imported modules that use their own instances internally. However, there is some cases of overriding (this example requires scoped type variables):<br />
module Example where {<br />
value1 :: Int;<br />
value1 = 2 + 3;<br />
value2 :: (Num x, x ~ Int) => x;<br />
value2 = ((+) :: x -> x -> x) 2 3;<br />
}<br />
module Main where {<br />
import Example;<br />
instance Num Int where {<br />
_ + _ = 42;<br />
};<br />
main = print (value1, value2);<br />
}<br />
The result will be:<br />
(5, 42)</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_instance_disambiguationUser:Zzo38/Proposal for instance disambiguation2011-11-20T06:22:36Z<p>Zzo38: </p>
<hr />
<div>This document has some of my ideas about instance disambiguations and related things how it could be implemented in Haskell.<br />
<br />
=Select instances from imported modules=<br />
Example:<br />
import A () instance ();<br />
import B class (AAA as ZZZ qualified as HHH);<br />
import C hiding instance (Num String, Num Bool);<br />
import D type (T as TT, U as newtype UU);<br />
From module A imports nothing not even instances. From module B imports instances of class AAA to be instances of class ZZZ instead, where all its methods are prefixed with "HHH." at the front. From module C, does not import instances of Num class for type String (this is only valid if type synonym instances is enabled, and means the same thing here) and Bool. From module D, the type named T is named TT when imported, for all functions using it, all instances, etc. If T is a type from a different module, then all function and instance from D using type T will make a new type TT instead. Instances for the type U are instead for a new type UU which is U wrapped in a newtype.<br />
<br />
=Override instances=<br />
Example:<br />
import E hiding module C;<br />
This hides instances in C which conflict with those of E, and hides names (except qualified)<br />
<br />
Example:<br />
instance Num Int where {<br />
x + y = 42;<br />
};<br />
This, defined in a module, automatically overrides instances from imported modules.<br />
<br />
Example:<br />
instance (instance IsString [Char] hiding) => IsString [x];<br />
It means that this is instance for any list but if there is instance for strings, that one will override this one.<br />
<br />
Example:<br />
instance Num x => Monoid (x as newtype (Sum x)) where {<br />
mempty = 0;<br />
mappend = (+);<br />
};<br />
Allows you to define newtype as part of an instance declaration, doing wrapping and unwrapping automatically.<br />
<br />
=Instance with imported modules=<br />
In general, you override instance, it doesn't affect functions from imported modules that use their own instances internally. However, there is some cases of overriding (this example requires scoped type variables):<br />
module Example where {<br />
value1 :: Int;<br />
value1 = 2 + 3;<br />
value2 :: (Num x, x ~ Int) => x;<br />
value2 = ((+) :: x -> x -> x) 2 3;<br />
}<br />
module Main where {<br />
import Example;<br />
instance Num Int where {<br />
_ + _ = 42;<br />
};<br />
main = print (value1, value2);<br />
}<br />
The result will be:<br />
(5, 42)</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_instance_disambiguationUser:Zzo38/Proposal for instance disambiguation2011-11-20T06:16:44Z<p>Zzo38: </p>
<hr />
<div>This document has some of my ideas about instance disambiguations and related things how it could be implemented in Haskell.<br />
<br />
=Select instances from imported modules=<br />
Example:<br />
import A () instance ();<br />
import B class (AAA as ZZZ qualified as HHH);<br />
import C hiding instance (Num String, Num Bool);<br />
import D type (T as TT, U as newtype UU);<br />
From module A imports nothing not even instances. From module B imports instances of class AAA to be instances of class ZZZ instead, where all its methods are prefixed with "HHH." at the front. From module C, does not import instances of Num class for type String (this is only valid if type synonym instances is enabled, and means the same thing here) and Bool. From module D, the type named T is named TT when imported, for all functions using it, all instances, etc. If T is a type from a different module, then all function and instance from D using type T will make a new type TT instead. Instances for the type U are instead for a new type UU which is U wrapped in a newtype.<br />
<br />
=Override instances=<br />
Example:<br />
import E hiding module C;<br />
This hides instances in C which conflict with those of E, and hides names (except qualified)<br />
<br />
Example:<br />
instance Num Int where {<br />
x + y = 42;<br />
};<br />
This, defined in a module, automatically overrides instances from imported modules.<br />
<br />
Example:<br />
instance (instance IsString [Char] hiding) => IsString [x];<br />
It means that this is instance for any list but if there is instance for strings, that one will override this one.<br />
<br />
Example:<br />
instance Num x => Monoid (x as newtype (Sum x)) where {<br />
mempty = 0;<br />
mappend = (+);<br />
};<br />
Allows you to define newtype as part of an instance declaration, doing wrapping and unwrapping automatically.</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_instance_disambiguationUser:Zzo38/Proposal for instance disambiguation2011-11-20T05:45:10Z<p>Zzo38: New page: This document has some of my ideas about instance disambiguations and related things how it could be implemented in Haskell. =Select instances from imported modules= Example: import A ()...</p>
<hr />
<div>This document has some of my ideas about instance disambiguations and related things how it could be implemented in Haskell.<br />
<br />
=Select instances from imported modules=<br />
Example:<br />
import A () instance ();<br />
import B class (AAA as ZZZ qualified as HHH);<br />
import C hiding instance (Num String, Num Bool);<br />
From module A imports nothing not even instances. From module B imports instances of class AAA to be instances of class ZZZ instead, where all its methods are prefixed with "HHH." at the front. From module C, does not import instances of Num class for type String (this is only valid if type synonym instances is enabled, and means the same thing here) and Bool.</div>Zzo38https://wiki.haskell.org/User:Zzo38User:Zzo382011-11-09T20:55:26Z<p>Zzo38: </p>
<hr />
<div>I am allowing all texts I typed into this wiki as public domain. The simple permissive license of Haskell Wiki is also permitted, so you can use that in case public domain is not possible.<br />
<br />
I have made one Haskell program so far:<br />
* [http://zzo38computer.cjb.net/prog/Constantinople.zip Constantinople compiler] (this program uses [[Parsec]] and [[Template Haskell]])<br />
<br />
Subpage:<br />
* [[User:Zzo38/Proposal for more-notation|Proposal for more-notation]]<br />
* [[User:Zzo38/Proposal about classes|Proposal about classes]]<br />
* [[User:Zzo38/Proposal for additional kinds|Proposal for additional kinds]]<br />
* [[User:Zzo38/Proposal for Haskell preprocessor|Proposal for Haskell preprocessor]]<br />
* [[User:Zzo38/Proposal for instance disambiguation|Proposal for instance disambiguation]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-09-16T19:55:53Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
In addition, parameters of a more-notation used in a field more-notation of a datatype declaration can be named <tt>_</tt> in which case that parameter can only be used to compute the value of the field, not the type of the field. It is also permitted in a field more-notation of a value construction or update syntax, which case that parameter is not used for value construction and can only be used to compute the type. If there is a parameter that is named <tt>_</tt> neither in the value or datatype declaration, then it has to be a type but you can use that type both in the type of the field and in types used for computing values of that field.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
A more-notation can go with quotations in both ways, and with splices in both ways. For example, you can have <tt>$(doThis 0 [more MoreDoThis])</tt> with declarations having to do with <tt>MoreDoThis</tt> outside of the splice.<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int<br />
<br />
==Purpose to use more-notation==<br />
<br />
===haskell-src-exts===<br />
In the <tt>ParseSyntax.hs</tt> file, everything has to be defined multiple times in different places, and in a common way. Using more-notation with Template Haskell could fix that. You could even put different extensions in different files and then combine them into one file.<br />
<br />
data PExp l<br />
= Var l (QName l) -- ^ variable<br />
| IPVar l (IPName l) -- ^ implicit parameter variable<br />
| Con l (QName l) -- ^ data constructor<br />
| Lit l (Literal l) -- ^ literal constant<br />
{- ... -}<br />
instance Annotated PExp where<br />
ann e = case e of<br />
Var l qn -> l<br />
IPVar l ipn -> l<br />
Con l qn -> l<br />
Lit l lit -> l<br />
{- ... -}<br />
amap f e = case e of<br />
Var l qn -> Var (f l) qn<br />
IPVar l ipn -> IPVar (f l) ipn<br />
Con l qn -> Con (f l) qn<br />
Lit l lit -> Lit (f l) lit<br />
<br />
As it might see, they are all written in many places, and the other ones are just written all in one way.<br />
<haskell><br />
data PExp l = more PExpConstructors l;<br />
instance Annotated PExp where {<br />
ann e = case e of more PExpAnnCases;<br />
amap f e = case e of more PExpAmapCases f;<br />
};<br />
let {<br />
convAnn :: Dec -> Dec;<br />
convAnn (MoreDataD _ _ _ c) = MoreCaseD ''PExpAnnCases NoOrder 'l $ fmap convAnn1 c;<br />
convAnn1 :: Con -> Match;<br />
convAnn1 (NormalC n t) = Match (ConP n $ (VarP 'l) : fmap (const WildP) (tail t)) (VarE 'l) [];<br />
} in do {<br />
MoreI _ _ _ m <- reify ''PExpConstructors;<br />
return $ fmap convAnn m;<br />
};<br />
</haskell><br />
<br />
===Magic Set Editor===<br />
In MSE, there are game templates, style templates, and export templates. Let's say you could somehow write them as a value in Haskell (MSE has some impure functions, but it is possible to make pure versions of those functions).<br />
<br />
You could have a card datatype like this (if the <tt>cardStyle</tt> is <tt>Nothing</tt> then it uses the default style for the set):<br />
data Card = Card { more CardFields, cardStyle :: Maybe Style };<br />
<br />
Now you can have styles.<br />
data Style = more Styles;<br />
renderStyle :: Style -> Render ();<br />
renderStyle s = case s of more StyleRenderers;<br />
<br />
The <tt>Render</tt> monad can allow you to retrieve card field values, as well as use do-notation with more-notation. You could then use the orders of the more-declarations to represent z-orders of fields.<br />
<br />
===Extensibility===<br />
<br />
===Literate programming===<br />
You might want a datatype or something else representing features of the program, and you might want to organize them into chapters. Therefore, you can define things in the chapter they belong.<br />
<br />
===Inform 7===<br />
<br />
==See also==<br />
* [[Extensible datatypes]]<br />
* [[Relative infix operator precedences]]<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-09-11T20:25:46Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
In addition, parameters of a more-notation used in a field more-notation of a datatype declaration can be named <tt>_</tt> in which case that parameter can only be used to compute the value of the field, not the type of the field. It is also permitted in a field more-notation of a value construction or update syntax, which case that parameter is not used for value construction and can only be used to compute the type. If there is a parameter that is named <tt>_</tt> neither in the value or datatype declaration, then it has to be a type but you can use that type both in the type of the field and in types used for computing values of that field.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int<br />
<br />
==Purpose to use more-notation==<br />
<br />
===haskell-src-exts===<br />
In the <tt>ParseSyntax.hs</tt> file, everything has to be defined multiple times in different places, and in a common way. Using more-notation with Template Haskell could fix that. You could even put different extensions in different files and then combine them into one file.<br />
<br />
data PExp l<br />
= Var l (QName l) -- ^ variable<br />
| IPVar l (IPName l) -- ^ implicit parameter variable<br />
| Con l (QName l) -- ^ data constructor<br />
| Lit l (Literal l) -- ^ literal constant<br />
{- ... -}<br />
instance Annotated PExp where<br />
ann e = case e of<br />
Var l qn -> l<br />
IPVar l ipn -> l<br />
Con l qn -> l<br />
Lit l lit -> l<br />
{- ... -}<br />
amap f e = case e of<br />
Var l qn -> Var (f l) qn<br />
IPVar l ipn -> IPVar (f l) ipn<br />
Con l qn -> Con (f l) qn<br />
Lit l lit -> Lit (f l) lit<br />
<br />
As it might see, they are all written in many places, and the other ones are just written all in one way.<br />
<haskell><br />
data PExp l = more PExpConstructors l;<br />
instance Annotated PExp where {<br />
ann e = case e of more PExpAnnCases;<br />
amap f e = case e of more PExpAmapCases f;<br />
};<br />
let {<br />
convAnn :: Dec -> Dec;<br />
convAnn (MoreDataD _ _ _ c) = MoreCaseD ''PExpAnnCases NoOrder 'l $ fmap convAnn1 c;<br />
convAnn1 :: Con -> Match;<br />
convAnn1 (NormalC n t) = Match (ConP n $ (VarP 'l) : fmap (const WildP) (tail t)) (VarE 'l) [];<br />
} in do {<br />
MoreI _ _ _ m <- reify ''PExpConstructors;<br />
return $ fmap convAnn m;<br />
};<br />
</haskell><br />
<br />
===Magic Set Editor===<br />
In MSE, there are game templates, style templates, and export templates. Let's say you could somehow write them as a value in Haskell (MSE has some impure functions, but it is possible to make pure versions of those functions).<br />
<br />
You could have a card datatype like this (if the <tt>cardStyle</tt> is <tt>Nothing</tt> then it uses the default style for the set):<br />
data Card = Card { more CardFields, cardStyle :: Maybe Style };<br />
<br />
Now you can have styles.<br />
data Style = more Styles;<br />
renderStyle :: Style -> Render ();<br />
renderStyle s = case s of more StyleRenderers;<br />
<br />
The <tt>Render</tt> monad can allow you to retrieve card field values, as well as use do-notation with more-notation. You could then use the orders of the more-declarations to represent z-orders of fields.<br />
<br />
===Extensibility===<br />
<br />
===Literate programming===<br />
You might want a datatype or something else representing features of the program, and you might want to organize them into chapters. Therefore, you can define things in the chapter they belong.<br />
<br />
===Inform 7===<br />
<br />
==See also==<br />
* [[Extensible datatypes]]<br />
* [[Relative infix operator precedences]]<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-09-11T16:55:44Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
In addition, parameters of a more-notation used in a field more-notation of a datatype declaration can be named <tt>_</tt> in which case that parameter can only be used to compute the value of the field, not the type of the field. It is also permitted in a field more-notation of a value construction or update syntax, which case that parameter is not used for value construction and can only be used to compute the type. If there is a parameter that is named <tt>_</tt> neither in the value or datatype declaration, then it has to be a type but you can use that type both in the type of the field and in types used for computing values of that field.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int<br />
<br />
==Purpose to use more-notation==<br />
<br />
===haskell-src-exts===<br />
In the <tt>ParseSyntax.hs</tt> file, everything has to be defined multiple times in different places, and in a common way. Using more-notation with Template Haskell could fix that. You could even put different extensions in different files and then combine them into one file.<br />
<br />
data PExp l<br />
= Var l (QName l) -- ^ variable<br />
| IPVar l (IPName l) -- ^ implicit parameter variable<br />
| Con l (QName l) -- ^ data constructor<br />
| Lit l (Literal l) -- ^ literal constant<br />
{- ... -}<br />
instance Annotated PExp where<br />
ann e = case e of<br />
Var l qn -> l<br />
IPVar l ipn -> l<br />
Con l qn -> l<br />
Lit l lit -> l<br />
{- ... -}<br />
amap f e = case e of<br />
Var l qn -> Var (f l) qn<br />
IPVar l ipn -> IPVar (f l) ipn<br />
Con l qn -> Con (f l) qn<br />
Lit l lit -> Lit (f l) lit<br />
<br />
As it might see, they are all written in many places, and the other ones are just written all in one way.<br />
<haskell><br />
data PExp l = more PExpConstructors l;<br />
instance Annotated PExp where {<br />
ann e = case e of more PExpAnnCases;<br />
amap f e = case e of more PExpAmapCases f;<br />
};<br />
let {<br />
convAnn :: Dec -> Dec;<br />
convAnn (MoreDataD _ _ _ c) = MoreCaseD ''PExpAnnCases NoOrder 'l $ fmap convAnn1 c;<br />
convAnn1 :: Con -> Match;<br />
convAnn1 (NormalC n t) = Match (ConP n $ (VarP 'l) : fmap (const WildP) (tail t)) (VarE 'l) [];<br />
} in do {<br />
MoreI _ _ _ m <- reify ''PExpConstructors;<br />
return $ fmap convAnn m;<br />
};<br />
</haskell><br />
<br />
===Magic Set Editor===<br />
In MSE, there are game templates, style templates, and export templates. Let's say you could somehow write them as a value in Haskell (MSE has some impure functions, but it is possible to make pure versions of those functions).<br />
<br />
You could have a card datatype like this (if the <tt>cardStyle</tt> is <tt>Nothing</tt> then it uses the default style for the set):<br />
data Card = Card { more CardFields, cardStyle :: Maybe Style };<br />
<br />
Now you can have styles.<br />
data Style = more Styles;<br />
renderStyle :: Style -> Render ();<br />
renderStyle s = case s of more StyleRenderers;<br />
<br />
The <tt>Render</tt> monad can allow you to retrieve card field values, as well as use do-notation with more-notation. You could then use the orders of the more-declarations to represent z-orders of fields.<br />
<br />
===Extensibility===<br />
<br />
===Literate programming===<br />
<br />
===Inform 7===<br />
<br />
==See also==<br />
* [[Extensible datatypes]]<br />
* [[Relative infix operator precedences]]<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-09-10T11:59:53Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int<br />
<br />
==Purpose to use more-notation==<br />
<br />
===haskell-src-exts===<br />
In the <tt>ParseSyntax.hs</tt> file, everything has to be defined multiple times in different places, and in a common way. Using more-notation with Template Haskell could fix that. You could even put different extensions in different files and then combine them into one file.<br />
<br />
data PExp l<br />
= Var l (QName l) -- ^ variable<br />
| IPVar l (IPName l) -- ^ implicit parameter variable<br />
| Con l (QName l) -- ^ data constructor<br />
| Lit l (Literal l) -- ^ literal constant<br />
{- ... -}<br />
instance Annotated PExp where<br />
ann e = case e of<br />
Var l qn -> l<br />
IPVar l ipn -> l<br />
Con l qn -> l<br />
Lit l lit -> l<br />
{- ... -}<br />
amap f e = case e of<br />
Var l qn -> Var (f l) qn<br />
IPVar l ipn -> IPVar (f l) ipn<br />
Con l qn -> Con (f l) qn<br />
Lit l lit -> Lit (f l) lit<br />
<br />
As it might see, they are all written in many places, and the other ones are just written all in one way.<br />
<haskell><br />
data PExp l = more PExpConstructors l;<br />
instance Annotated PExp where {<br />
ann e = case e of more PExpAnnCases;<br />
amap f e = case e of more PExpAmapCases f;<br />
};<br />
let {<br />
convAnn :: Dec -> Dec;<br />
convAnn (MoreDataD _ _ _ c) = MoreCaseD ''PExpAnnCases NoOrder 'l $ fmap convAnn1 c;<br />
convAnn1 :: Con -> Match;<br />
convAnn1 (NormalC n t) = Match (ConP n $ (VarP 'l) : fmap (const WildP) (tail t)) (VarE 'l) [];<br />
} in do {<br />
MoreI _ _ _ m <- reify ''PExpConstructors;<br />
return $ fmap convAnn m;<br />
};<br />
</haskell><br />
<br />
===Magic Set Editor===<br />
In MSE, there are game templates, style templates, and export templates. Let's say you could somehow write them as a value in Haskell (MSE has some impure functions, but it is possible to make pure versions of those functions).<br />
<br />
You could have a card datatype like this (if the <tt>cardStyle</tt> is <tt>Nothing</tt> then it uses the default style for the set):<br />
data Card = Card { more CardFields, cardStyle :: Maybe Style };<br />
<br />
Now you can have styles.<br />
data Style = more Styles;<br />
renderStyle :: Style -> Render ();<br />
renderStyle s = case s of more StyleRenderers;<br />
<br />
The <tt>Render</tt> monad can allow you to retrieve card field values, as well as use do-notation with more-notation. You could then use the orders of the more-declarations to represent z-orders of fields.<br />
<br />
===Extensibility===<br />
<br />
===Literate programming===<br />
<br />
===Inform 7===<br />
<br />
==See also==<br />
* [[Extensible datatypes]]<br />
* [[Relative infix operator precedences]]<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-09-10T03:33:41Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int<br />
<br />
==Purpose to use more-notation==<br />
<br />
===haskell-src-exts===<br />
In the <tt>ParseSyntax.hs</tt> file, everything has to be defined multiple times in different places, and in a common way. Using more-notation with Template Haskell could fix that. You could even put different extensions in different files and then combine them into one file.<br />
<br />
data PExp l<br />
= Var l (QName l) -- ^ variable<br />
| IPVar l (IPName l) -- ^ implicit parameter variable<br />
| Con l (QName l) -- ^ data constructor<br />
| Lit l (Literal l) -- ^ literal constant<br />
{- ... -}<br />
instance Annotated PExp where<br />
ann e = case e of<br />
Var l qn -> l<br />
IPVar l ipn -> l<br />
Con l qn -> l<br />
Lit l lit -> l<br />
{- ... -}<br />
amap f e = case e of<br />
Var l qn -> Var (f l) qn<br />
IPVar l ipn -> IPVar (f l) ipn<br />
Con l qn -> Con (f l) qn<br />
Lit l lit -> Lit (f l) lit<br />
<br />
As it might see, they are all written in many places, and the other ones are just written all in one way.<br />
<haskell><br />
data PExp l = more PExpConstructors l;<br />
instance Annotated PExp where {<br />
ann e = case e of more PExpAnnCases;<br />
amap f e = case e of more PExpAmapCases f;<br />
};<br />
let {<br />
convAnn :: Dec -> Dec;<br />
convAnn (MoreDataD _ _ _ c) = MoreCaseD ''PExpAnnCases NoOrder 'l $ fmap convAnn1 c;<br />
convAnn1 :: Con -> Match;<br />
convAnn1 (NormalC n t) = Match (ConP n $ (VarP 'l) : fmap (const WildP) (tail t)) (VarE 'l) [];<br />
} in do {<br />
MoreI _ _ _ m <- reify ''PExpConstructors;<br />
return $ fmap convAnn m;<br />
};<br />
</haskell><br />
<br />
===Magic Set Editor===<br />
In MSE, there are game templates, style templates, and export templates. Let's say you could somehow write them as a value in Haskell (MSE has some impure functions, but it is possible to make pure versions of those functions).<br />
<br />
You could have a card datatype like this (if the <tt>cardStyle</tt> is <tt>Nothing</tt> then it uses the default style for the set):<br />
data Card = Card { more CardFields, cardStyle :: Maybe Style };<br />
<br />
Now you can have styles.<br />
data Style = more Styles;<br />
renderStyle :: Style -> Render ();<br />
renderStyle s = case s of more StyleRenderers;<br />
<br />
The <tt>Render</tt> monad can allow you to retrieve card field values, as well as use do-notation with more-notation. You could then use the orders of the more-declarations to represent z-orders of fields.<br />
<br />
===Extensibility===<br />
<br />
===Literate programming===<br />
<br />
===Inform 7===<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38User:Zzo382011-09-10T01:04:01Z<p>Zzo38: </p>
<hr />
<div>I am allowing all texts I typed into this wiki as public domain. The simple permissive license of Haskell Wiki is also permitted, so you can use that in case public domain is not possible.<br />
<br />
I have made one Haskell program so far:<br />
* [http://zzo38computer.cjb.net/prog/Constantinople.zip Constantinople compiler] (this program uses [[Parsec]] and [[Template Haskell]])<br />
<br />
Subpage:<br />
* [[User:Zzo38/Proposal for more-notation|Proposal for more-notation]]<br />
* [[User:Zzo38/Proposal about classes|Proposal about classes]]<br />
* [[User:Zzo38/Proposal for additional kinds|Proposal for additional kinds]]<br />
* [[User:Zzo38/Proposal for Haskell preprocessor|Proposal for Haskell preprocessor]]</div>Zzo38https://wiki.haskell.org/User:Zzo38User:Zzo382011-09-10T01:02:26Z<p>Zzo38: </p>
<hr />
<div>I am allowing all texts I typed into this wiki as public domain.<br />
<br />
I have made one Haskell program so far:<br />
* [http://zzo38computer.cjb.net/prog/Constantinople.zip Constantinople compiler] (this program uses [[Parsec]] and [[Template Haskell]])<br />
<br />
Subpage:<br />
* [[User:Zzo38/Proposal for more-notation|Proposal for more-notation]]<br />
* [[User:Zzo38/Proposal about classes|Proposal about classes]]<br />
* [[User:Zzo38/Proposal for additional kinds|Proposal for additional kinds]]<br />
* [[User:Zzo38/Proposal for Haskell preprocessor|Proposal for Haskell preprocessor]]</div>Zzo38https://wiki.haskell.org/User:Zzo38User:Zzo382011-09-10T01:02:15Z<p>Zzo38: </p>
<hr />
<div>I am license all texts I typed into this wiki as public domain.<br />
<br />
I have made one Haskell program so far:<br />
* [http://zzo38computer.cjb.net/prog/Constantinople.zip Constantinople compiler] (this program uses [[Parsec]] and [[Template Haskell]])<br />
<br />
Subpage:<br />
* [[User:Zzo38/Proposal for more-notation|Proposal for more-notation]]<br />
* [[User:Zzo38/Proposal about classes|Proposal about classes]]<br />
* [[User:Zzo38/Proposal for additional kinds|Proposal for additional kinds]]<br />
* [[User:Zzo38/Proposal for Haskell preprocessor|Proposal for Haskell preprocessor]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-09-09T20:46:48Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int<br />
<br />
==Purpose to use more-notation==<br />
<br />
===haskell-src-exts===<br />
In the <tt>ParseSyntax.hs</tt> file, everything has to be defined multiple times in different places, and in a common way. Using more-notation with Template Haskell could fix that. You could even put different extensions in different files and then combine them into one file.<br />
<br />
data PExp l<br />
= Var l (QName l) -- ^ variable<br />
| IPVar l (IPName l) -- ^ implicit parameter variable<br />
| Con l (QName l) -- ^ data constructor<br />
| Lit l (Literal l) -- ^ literal constant<br />
{- ... -}<br />
instance Annotated PExp where<br />
ann e = case e of<br />
Var l qn -> l<br />
IPVar l ipn -> l<br />
Con l qn -> l<br />
Lit l lit -> l<br />
{- ... -}<br />
amap f e = case e of<br />
Var l qn -> Var (f l) qn<br />
IPVar l ipn -> IPVar (f l) ipn<br />
Con l qn -> Con (f l) qn<br />
Lit l lit -> Lit (f l) lit<br />
<br />
As it might see, they are all written in many places, and the other ones are just written all in one way.<br />
<haskell><br />
data PExp l = more PExpConstructors l;<br />
instance Annotated PExp where {<br />
ann e = case e of more PExpAnnCases;<br />
amap f e = case e of more PExpAmapCases;<br />
};<br />
let {<br />
convAnn :: Dec -> Dec;<br />
convAnn (MoreDataD _ _ _ c) = MoreCaseD ''PExpAnnCases NoOrder 'l $ fmap convAnn1 c;<br />
convAnn1 :: Con -> Match;<br />
convAnn1 (NormalC n t) = Match (ConP n $ (VarP 'l) : fmap (const WildP) (tail t)) (VarE 'l) [];<br />
} in do {<br />
MoreI _ _ _ m <- reify ''PExpConstructors;<br />
return $ fmap convAnn m;<br />
};<br />
</haskell><br />
<br />
===Magic Set Editor===<br />
In MSE, there are game templates, style templates, and export templates. Let's say you could somehow write them as a value in Haskell (MSE has some impure functions, but it is possible to make pure versions of those functions).<br />
<br />
You could have a card datatype like this (if the <tt>cardStyle</tt> is <tt>Nothing</tt> then it uses the default style for the set):<br />
data Card = Card { more CardFields, cardStyle :: Maybe Style };<br />
<br />
Now you can have styles.<br />
data Style = more Styles;<br />
renderStyle :: Style -> Render ();<br />
renderStyle s = case s of more StyleRenderers;<br />
<br />
The <tt>Render</tt> monad can allow you to retrieve card field values, as well as use do-notation with more-notation. You could then use the orders of the more-declarations to represent z-orders of fields.<br />
<br />
===Extensibility===<br />
<br />
===Literate programming===<br />
<br />
===Inform 7===<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-09-09T20:20:23Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int<br />
<br />
==Purpose to use more-notation==<br />
<br />
===haskell-src-exts===<br />
In the <tt>ParseSyntax.hs</tt> file, everything has to be defined multiple times in different places, and in a common way. Using more-notation with Template Haskell could fix that. You could even put different extensions in different files and then combine them into one file.<br />
<br />
data PExp l<br />
= Var l (QName l) -- ^ variable<br />
| IPVar l (IPName l) -- ^ implicit parameter variable<br />
| Con l (QName l) -- ^ data constructor<br />
| Lit l (Literal l) -- ^ literal constant<br />
{- ... -}<br />
instance Annotated PExp where<br />
ann e = case e of<br />
Var l qn -> l<br />
IPVar l ipn -> l<br />
Con l qn -> l<br />
Lit l lit -> l<br />
{- ... -}<br />
amap f e = case e of<br />
Var l qn -> Var (f l) qn<br />
IPVar l ipn -> IPVar (f l) ipn<br />
Con l qn -> Con (f l) qn<br />
Lit l lit -> Lit (f l) lit<br />
<br />
As it might see, they are all written in many places, and the other ones are just written all in one way.<br />
<haskell><br />
data PExp l = more PExpConstructors l;<br />
instance Annotated PExp where {<br />
ann e = case e of more PExpAnnCases;<br />
amap f e = case e of more PExpAmapCases;<br />
};<br />
let {<br />
convAnn :: Dec -> Dec;<br />
convAnn (MoreDataD _ _ _ c) = MoreCaseD ''PExpAnnCases NoOrder 'l $ fmap convAnn1 c;<br />
convAnn1 :: Con -> Match;<br />
convAnn1 (NormalC n t) = Match (ConP n $ (VarP 'l) : fmap (const WildP) (tail t)) (VarE 'l) [];<br />
} in do {<br />
MoreI _ _ _ m <- reify ''PExpConstructors;<br />
return $ fmap convAnn m;<br />
};<br />
</haskell><br />
<br />
===Magic Set Editor===<br />
<br />
===Extensibility===<br />
<br />
===Literate programming===<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-09-09T20:19:29Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int<br />
<br />
==Purpose to use more-notation==<br />
<br />
===haskell-src-exts===<br />
In the <tt>ParseSyntax.hs</tt> file, everything has to be defined multiple times in different places, and in a common way. Using more-notation with Template Haskell could fix that. You could even put different extensions in different files and then combine them into one file.<br />
<br />
data PExp l<br />
= Var l (QName l) -- ^ variable<br />
| IPVar l (IPName l) -- ^ implicit parameter variable<br />
| Con l (QName l) -- ^ data constructor<br />
| Lit l (Literal l) -- ^ literal constant<br />
{- ... -}<br />
instance Annotated PExp where<br />
ann e = case e of<br />
Var l qn -> l<br />
IPVar l ipn -> l<br />
Con l qn -> l<br />
Lit l lit -> l<br />
{- ... -}<br />
amap f e = case e of<br />
Var l qn -> Var (f l) qn<br />
IPVar l ipn -> IPVar (f l) ipn<br />
Con l qn -> Con (f l) qn<br />
Lit l lit -> Lit (f l) lit<br />
<br />
As it might see, they are all written in many places, and the other ones are just written all in one way.<br />
<br />
data PExp l = more PExpConstructors l;<br />
instance Annotated PExp where {<br />
ann e = case e of more PExpAnnCases;<br />
amap f e = case e of more PExpAmapCases;<br />
};<br />
let {<br />
convAnn :: Dec -> Dec;<br />
convAnn (MoreDataD _ _ _ c) = MoreCaseD ''PExpAnnCases NoOrder 'l $ fmap convAnn1 c;<br />
convAnn1 :: Con -> Match;<br />
convAnn1 (NormalC n t) = Match (ConP n $ (VarP 'l) : fmap (const WildP) (tail t)) (VarE 'l) [];<br />
} in do {<br />
MoreI _ _ _ m <- reify ''PExpConstructors;<br />
return $ fmap convAnn m;<br />
};<br />
<br />
===Magic Set Editor===<br />
<br />
===Extensibility===<br />
<br />
===Literate programming===<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_additional_kindsUser:Zzo38/Proposal for additional kinds2011-09-05T01:50:35Z<p>Zzo38: </p>
<hr />
<div>This document is proposal about additional kinds.<br />
<br />
==New kinds==<br />
## -- New name for (#) kind (although (#) is available for compatibility)<br />
& -- Kind for classes<br />
+ -- Kind for type-level natural numbers<br />
$ -- Means make up a kind from a Template Haskell code<br />
<br />
==Kind of classes==<br />
Example:<br />
* -> & -- Kind of Eq class.<br />
(* -> *) -> & -- Kind of Monad class.<br />
(* -> &) -> & -- Class of classes.<br />
+ -> * -> & -- Infinite series of classes, selected by a natural number.<br />
<br />
==Natural number kind==<br />
If a type requires a parameter, it can be a <tt>+</tt> kind, meaning numbers.<br />
<br />
There should be some way to specify a type taking natural numbers by defining it for zero and them for a successor, so that it applies for all natural numbers.<br />
<br />
It also means a type of kind <tt>+ -> + -> +</tt> can be a type of adding numbers or other stuff like that, too.<br />
<br />
==See also==<br />
* [http://hackage.haskell.org/trac/ghc/wiki/KindFact KindFact]<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_additional_kindsUser:Zzo38/Proposal for additional kinds2011-09-05T01:48:14Z<p>Zzo38: </p>
<hr />
<div>This document is proposal about additional kinds.<br />
<br />
==New kinds==<br />
## -- New name for (#) kind (although (#) is available for compatibility)<br />
& -- Kind for classes<br />
+ -- Kind for type-level natural numbers<br />
$ -- Means make up a kind from a Template Haskell code<br />
<br />
==Kind of classes==<br />
Example:<br />
* -> & -- Kind of Eq class.<br />
(* -> *) -> & -- Kind of Monad class.<br />
(* -> &) -> & -- Class of classes.<br />
+ -> * -> & -- Infinite series of classes, selected by a natural number.<br />
<br />
==Natural number kind==<br />
If a type requires a parameter, it can be a <tt>+</tt> kind, meaning numbers.<br />
<br />
There should be some way to specify a type taking natural numbers by defining it for zero and them for a successor, so that it applies for all natural numbers.<br />
<br />
It also means a type of kind <tt>+ -> + -> +</tt> can be a type of adding numbers or other stuff like that, too.<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_about_classesUser:Zzo38/Proposal about classes2011-09-04T05:09:18Z<p>Zzo38: </p>
<hr />
<div>This document is proposal relating to various things dealing with classes in Haskell.<br />
<br />
==Monads==<br />
Move <tt>join</tt> into the <tt>Monad</tt> class, to allow monads to defined in terms of unit/join/fmap. Together with things described below, it can automatically be <tt>Functor</tt> as well, and define <tt>fmap</tt> if you are using return/bind definitions.<br />
<br />
==Default superclass definitions==<br />
For example, for monads you can have:<br />
class Functor m => Monad (m :: * -> *) where {<br />
(>>=) :: forall a b. m a -> (a -> m b) -> m b;<br />
(>>) :: forall a b. m a -> m b -> m b;<br />
return :: a -> m a;<br />
join :: m (m a) -> m a;<br />
fail :: String -> m a;<br />
<br />
a >>= f = join $ fmap f a;<br />
m >> k = m >>= \_ -> k;<br />
join = (>>= id);<br />
fail = error;<br />
<br />
fmap f m = m >>= return . f;<br />
};<br />
<br />
In this case, you can define the defaults for <tt>Functor</tt> if they are not already defined.<br />
<br />
==Restrictive classes==<br />
For example, make a restrictive monad that only contains instances of <tt>Ord</tt>. I am not sure about syntax or other details.<br />
<br />
==Classes of classes==<br />
See proposal of kinds.<br />
<br />
==Universal class==<br />
There can be one universal class that all types automatically belong to. This is a polymorphic class (see proposal of kinds) of kind <tt>forall k. [k]</tt>; that is, it is for any kind (including other classes).<br />
<br />
==Generalize an existing class==<br />
<!-- class RestrictMonad (UniversalClass :: [*]) <- Monad; --><br />
<br />
==Automatic instances==<br />
You can have a Template Haskell command, that takes a name of class, and a function that uses the definition of a type to make up a instance declaration for that class. If there is no such instance, it tries to make up the instance using that function. If it results in <tt>fail</tt>, then it is error as if there is no instance normally, but the fail message is also displayed.<br />
<br />
==See also==<br />
* [[Superclass defaults]]<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_additional_kindsUser:Zzo38/Proposal for additional kinds2011-09-03T21:58:47Z<p>Zzo38: </p>
<hr />
<div>This document is proposal about additional kinds.<br />
<br />
==New kinds==<br />
## -- New name for (#) kind (although (#) is available for compatibility)<br />
[x] -- If x is a kind, [x] is the kind of classes of types of kind x<br />
+ -- Kind for type-level natural numbers<br />
$ -- Means make up a kind from a Template Haskell code<br />
<br />
==Kind of classes==<br />
Example:<br />
[*] -- Kind of Eq class.<br />
[* -> *] -- Kind of Monad class.<br />
* -> [*] -- A class that requires a type as a parameter to make a class.<br />
[<b></b>[*]] -- Class of classes.<br />
+ -> [*] -- Infinite series of classes, selected by a natural number.<br />
k -> [k] -- Polymorphic class that corresponds to any given kind.<br />
<!-- <b></b> means make it appear correctly on HTML view --><br />
<br />
==Natural number kind==<br />
If a type requires a parameter, it can be a <tt>+</tt> kind, meaning numbers.<br />
<br />
There should be some way to specify a type taking natural numbers by defining it for zero and them for a successor, so that it applies for all natural numbers.<br />
<br />
It also means a type of kind <tt>+ -> + -> +</tt> can be a type of adding numbers or other stuff like that, too.<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_additional_kindsUser:Zzo38/Proposal for additional kinds2011-09-03T21:58:39Z<p>Zzo38: </p>
<hr />
<div>This document is proposal about additional kinds.<br />
<br />
==New kinds==<br />
## -- New name for (#) kind (although (#) is available for compatibility)<br />
[x] -- If x is a kind, [x] is the kind of classes of types of kind x<br />
+ -- Kind for type-level natural numbers<br />
$ -- Means make up a kind from a Template Haskell code<br />
<br />
==Kind of classes==<br />
Example:<br />
[*] -- Kind of Eq class.<br />
[* -> *] -- Kind of Monad class.<br />
* -> [*] -- A class that requires a type as a parameter to make a class.<br />
[<b></b>[*]] -- Class of classes.<br />
+ -> [*] -- Infinite series of classes, selected by a natural number.<br />
forall k. k -> [k] -- Polymorphic class that corresponds to any given kind.<br />
<!-- <b></b> means make it appear correctly on HTML view --><br />
<br />
==Natural number kind==<br />
If a type requires a parameter, it can be a <tt>+</tt> kind, meaning numbers.<br />
<br />
There should be some way to specify a type taking natural numbers by defining it for zero and them for a successor, so that it applies for all natural numbers.<br />
<br />
It also means a type of kind <tt>+ -> + -> +</tt> can be a type of adding numbers or other stuff like that, too.<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38User:Zzo382011-09-03T20:40:51Z<p>Zzo38: </p>
<hr />
<div>I have made one Haskell program so far:<br />
* [http://zzo38computer.cjb.net/prog/Constantinople.zip Constantinople compiler] (this program uses [[Parsec]] and [[Template Haskell]])<br />
<br />
Subpage:<br />
* [[User:Zzo38/Proposal for more-notation|Proposal for more-notation]]<br />
* [[User:Zzo38/Proposal about classes|Proposal about classes]]<br />
* [[User:Zzo38/Proposal for additional kinds|Proposal for additional kinds]]<br />
* [[User:Zzo38/Proposal for Haskell preprocessor|Proposal for Haskell preprocessor]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_additional_kindsUser:Zzo38/Proposal for additional kinds2011-09-03T20:38:11Z<p>Zzo38: </p>
<hr />
<div>This document is proposal about additional kinds.<br />
<br />
==New kinds==<br />
## -- New name for (#) kind (although (#) is available for compatibility)<br />
[x] -- If x is a kind, [x] is the kind of classes of types of kind x<br />
+ -- Kind for type-level natural numbers<br />
<br />
==Kind of classes==<br />
Example:<br />
[*] -- Kind of Eq class.<br />
[* -> *] -- Kind of Monad class.<br />
* -> [*] -- A class that requires a type as a parameter to make a class.<br />
[<b></b>[*]] -- Class of classes.<br />
<!-- <b></b> means make it appear correctly on HTML view --><br />
<br />
==Natural number kind==<br />
If a type requires a parameter, it can be a <tt>+</tt> kind, meaning numbers.<br />
<br />
There should be some way to specify a type taking natural numbers by defining it for zero and them for a successor, so that it applies for all natural numbers.<br />
<br />
It also means a type of kind <tt>+ -> + -> +</tt> can be a type of adding numbers or other stuff like that, too.<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_about_classesUser:Zzo38/Proposal about classes2011-09-03T20:34:38Z<p>Zzo38: </p>
<hr />
<div>This document is proposal relating to various things dealing with classes in Haskell.<br />
<br />
==Monads==<br />
Move <tt>join</tt> into the <tt>Monad</tt> class, to allow monads to defined in terms of unit/join/fmap. Together with things described below, it can automatically be <tt>Functor</tt> as well, and define <tt>fmap</tt> if you are using return/bind definitions.<br />
<br />
==Default superclass definitions==<br />
For example, for monads you can have:<br />
class Functor m => Monad (m :: * -> *) where {<br />
(>>=) :: forall a b. m a -> (a -> m b) -> m b;<br />
(>>) :: forall a b. m a -> m b -> m b;<br />
return :: a -> m a;<br />
join :: m (m a) -> m a;<br />
fail :: String -> m a;<br />
<br />
a >>= f = join $ fmap f a;<br />
m >> k = m >>= \_ -> k;<br />
join = (>>= id);<br />
fail = error;<br />
<br />
fmap f m = m >>= return . f;<br />
};<br />
<br />
In this case, you can define the defaults for <tt>Functor</tt> if they are not already defined.<br />
<br />
==Restrictive classes==<br />
For example, make a restrictive monad that only contains instances of <tt>Ord</tt>. I am not sure about syntax or other details.<br />
<br />
==Classes of classes==<br />
See proposal of kinds.<br />
<br />
==Automatic instances==<br />
You can have a Template Haskell command, that takes a name of class, and a function that uses the definition of a type to make up a instance declaration for that class. If there is no such instance, it tries to make up the instance using that function. If it results in <tt>fail</tt>, then it is error as if there is no instance normally, but the fail message is also displayed.<br />
<br />
==See also==<br />
* [[Superclass defaults]]<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_additional_kindsUser:Zzo38/Proposal for additional kinds2011-09-03T20:30:53Z<p>Zzo38: </p>
<hr />
<div>This document is proposal about additional kinds.<br />
<br />
==New kinds==<br />
## -- New name for (#) kind (although (#) is available for compatibility)<br />
[x] -- If x is a kind, [x] is the kind of classes of types of kind x<br />
+ -- Kind for type-level natural numbers<br />
<br />
==Kind of classes==<br />
Example:<br />
[*] -- Kind of Eq class.<br />
[* -> *] -- Kind of Monad class.<br />
* -> [*] -- A class that requires a type as a parameter to make a class.<br />
[<b></b>[*]] -- Class of classes.<br />
<!-- <b></b> means make it appear correctly on HTML view --><br />
<br />
==Natural number kind==<br />
If a type requires a parameter, it can be a <tt>+</tt> kind, meaning numbers.<br />
<br />
There should be some way to specify a type taking natural numbers by defining it for zero and them for a successor, so that it applies for all natural numbers.<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-09-03T20:29:08Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_about_classesUser:Zzo38/Proposal about classes2011-09-03T20:28:47Z<p>Zzo38: </p>
<hr />
<div>This document is proposal relating to various things dealing with classes in Haskell.<br />
<br />
==Monads==<br />
Move <tt>join</tt> into the <tt>Monad</tt> class, to allow monads to defined in terms of unit/join/fmap. Together with things described below, it can automatically be <tt>Functor</tt> as well, and define <tt>fmap</tt> if you are using return/bind definitions.<br />
<br />
==Default superclass definitions==<br />
For example, for monads you can have:<br />
class Functor m => Monad (m :: * -> *) where {<br />
(>>=) :: forall a b. m a -> (a -> m b) -> m b;<br />
(>>) :: forall a b. m a -> m b -> m b;<br />
return :: a -> m a;<br />
join :: m (m a) -> m a;<br />
fail :: String -> m a;<br />
<br />
a >>= f = join $ fmap f a;<br />
m >> k = m >>= \_ -> k;<br />
join = (>>= id);<br />
fail = error;<br />
<br />
fmap f m = m >>= return . f;<br />
};<br />
<br />
In this case, you can define the defaults for <tt>Functor</tt> if they are not already defined.<br />
<br />
==Restrictive classes==<br />
For example, make a restrictive monad that only contains instances of <tt>Ord</tt>. I am not sure about syntax or other details.<br />
<br />
==Classes of classes==<br />
See proposal of kinds.<br />
<br />
==See also==<br />
* [[Superclass defaults]]<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_additional_kindsUser:Zzo38/Proposal for additional kinds2011-09-03T20:27:54Z<p>Zzo38: New page: This document is proposal about additional kinds. ==New kinds== ## -- New name for (#) kind (although (#) is available for compatibility) [x] -- If x is a kind, [x] is the kind...</p>
<hr />
<div>This document is proposal about additional kinds.<br />
<br />
==New kinds==<br />
## -- New name for (#) kind (although (#) is available for compatibility)<br />
[x] -- If x is a kind, [x] is the kind of classes of types of kind x<br />
+ -- Kind for type-level natural numbers<br />
<br />
==Kind of classes==<br />
Example:<br />
[*] -- Kind of Eq class.<br />
[* -> *] -- Kind of Monad class.<br />
* -> [*] -- A class that requires a type as a parameter to make a class.<br />
[[*]] -- Class of classes.<br />
<br />
==Natural number kind==<br />
If a type requires a parameter, it can be a <tt>+</tt> kind, meaning numbers.<br />
<br />
There should be some way to specify a type taking natural numbers by defining it for zero and them for a successor, so that it applies for all natural numbers.<br />
<br />
[[Category:Proposals]]</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_about_classesUser:Zzo38/Proposal about classes2011-09-03T20:17:28Z<p>Zzo38: </p>
<hr />
<div>This document is proposal relating to various things dealing with classes in Haskell.<br />
<br />
==Monads==<br />
Move <tt>join</tt> into the <tt>Monad</tt> class, to allow monads to defined in terms of unit/join/fmap. Together with things described below, it can automatically be <tt>Functor</tt> as well, and define <tt>fmap</tt> if you are using return/bind definitions.<br />
<br />
==Default superclass definitions==<br />
For example, for monads you can have:<br />
class Functor m => Monad (m :: * -> *) where {<br />
(>>=) :: forall a b. m a -> (a -> m b) -> m b;<br />
(>>) :: forall a b. m a -> m b -> m b;<br />
return :: a -> m a;<br />
join :: m (m a) -> m a;<br />
fail :: String -> m a;<br />
<br />
a >>= f = join $ fmap f a;<br />
m >> k = m >>= \_ -> k;<br />
join = (>>= id);<br />
fail = error;<br />
<br />
fmap f m = m >>= return . f;<br />
};<br />
<br />
In this case, you can define the defaults for <tt>Functor</tt> if they are not already defined.<br />
<br />
==Restrictive classes==<br />
For example, make a restrictive monad that only contains instances of <tt>Ord</tt>. I am not sure about syntax or other details.<br />
<br />
==Classes of classes==<br />
See proposal of kinds.</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_about_classesUser:Zzo38/Proposal about classes2011-09-03T20:17:15Z<p>Zzo38: New page: This document is proposal relating to various things dealing with classes in Haskell. ==Monads== Move <tt>join</tt> into the <tt>Monad</tt> class, to allow monads to defined in terms of u...</p>
<hr />
<div>This document is proposal relating to various things dealing with classes in Haskell.<br />
<br />
==Monads==<br />
Move <tt>join</tt> into the <tt>Monad</tt> class, to allow monads to defined in terms of unit/join/fmap. Together with things described below, it can automatically be <tt>Functor</tt> as well, and define <tt>fmap</tt> if you are using return/bind definitions.<br />
<br />
==Default superclass definitions==<br />
For example, for monads you can have:<br />
class Functor m => Monad (m :: * -> *) where {<br />
(>>=) :: forall a b. m a -> (a -> m b) -> m b;<br />
(>>) :: forall a b. m a -> m b -> m b;<br />
return :: a -> m a;<br />
join :: m (m a) -> m a;<br />
fail :: String -> m a;<br />
<br />
a >>= f = join $ fmap f a;<br />
m >> k = m >>= \_ -> k;<br />
join = (>>= id);<br />
fail = error;<br />
<br />
fmap f m = m >>= return . f;<br />
};<br />
<br />
In this case, you can define the defaults for <tt>Functor</tt> if they are not already defined.<br />
<br />
==Restrictive classes==<br />
For example, make a restrictive monad that only contains instances of <tt>Ord</tt>. I am not sure about syntax or other details.<br />
<br />
==Classes of classes==<br />
See proposal of kinds.</div>Zzo38https://wiki.haskell.org/User:Zzo38User:Zzo382011-09-03T19:38:04Z<p>Zzo38: </p>
<hr />
<div>I have made one Haskell program so far:<br />
* [http://zzo38computer.cjb.net/prog/Constantinople.zip Constantinople compiler] (this program uses [[Parsec]] and [[Template Haskell]])<br />
<br />
Subpage:<br />
* [[User:Zzo38/Proposal for more-notation|Proposal for more-notation]]<br />
* [[User:Zzo38/Proposal about classes|Proposal about classes]]<br />
* [[User:Zzo38/Proposal for additional kinds|Proposal for additional kinds]]</div>Zzo38https://wiki.haskell.org/QuasiquotationQuasiquotation2011-09-02T19:02:23Z<p>Zzo38: </p>
<hr />
<div>This is a tutorial for the quasiquoting facility described in<br />
[http://www.eecs.harvard.edu/~mainland/ghc-quasiquoting/mainland07quasiquoting.pdf Why It's Nice to be Quoted: Quasiquoting for Haskell].<br />
<br />
Quasiquoting allows programmers to use custom, domain-specific syntax to construct fragments of their program. Along with Haskell's existing support for domain specific languages, you are now free to use new syntactic forms for your EDSLs.<br />
<br />
More information on GHC's support for quasiquoting may be found:<br />
<br />
* [http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.html#th-quasiquotation Using QQ with Template Haskell]<br />
* [http://www.eecs.harvard.edu/~mainland/ghc-quasiquoting/mainland07quasiquoting.pdf Why It's Nice to be Quoted: Quasiquoting for Haskell] :: PDF<br />
<br />
And a number of production examples:<br />
<br />
* The [[jmacro]] JavaScript generation library.<br />
* [http://hackage.haskell.org/package/interpolatedstring-qq Quasiquoter for Ruby-style interpolated strings]<br />
* [http://hackage.haskell.org/package/interpolatedstring-perl6 interpolatedstring-perl6 library: QuasiQuoter for Perl6-style multi-line interpolated strings with "q"]<br />
* [http://hackage.haskell.org/package/regexqq Quasiquoter for regular expressions]<br />
* [http://hackage.haskell.org/package/lighttpd-conf-qq A QuasiQuoter for lighttpd configuration files]<br />
* [http://hackage.haskell.org/package/haskell-src-meta haskell-src-meta contains quite a few QuasiQuoters]<br />
<br />
Note that the syntax for quasiquotation has changed since the paper was written: in GHC 7 one writes <hask>[expr|...|]</hask> instead of <hask>[:expr|...|]</hask>. GHC 6.12 uses <hask>[$expr|...|]</hask>. Quasiquotation appeared in GHC 6.9 and is enabled with the <code>QuasiQuotes</code> language option (<code>-XQuasiQuotes</code> on the command line or <hask>{-# LANGUAGE QuasiQuotes #-}</hask> in a source file).<br />
<br />
We show how to build a quasiquoter for a simple mathematical expression<br />
language. Although the example is small, it demonstrates all aspects of building<br />
a quasiquoter. We do not mean to suggest that one gains much from a quasiquoter<br />
for such a small language relative to using abstract syntax directly except from<br />
a pedagogical point of view---this is just a tutorial!<br />
<br />
The tutorial is runnable if its contents is placed in files as follows:<br />
<br />
Place the contents of the [[#Syntax]] and [[#Parsing]] sections in the file <code>Expr.hs</code><br />
with header<br />
<br />
<haskell><br />
{-# LANGUAGE DeriveDataTypeable #-}<br />
module Expr (Expr(..),<br />
BinOp(..),<br />
eval,<br />
parseExpr)<br />
where<br />
<br />
import Data.Generics<br />
import Text.ParserCombinators.Parsec<br />
</haskell><br />
<br />
Place the contents of the section [[#The Quasiquoter]] in a<br />
file <code>Expr/Quote.hs</code> with header<br />
<br />
<haskell><br />
module Expr.Quote (expr) where<br />
<br />
import Data.Generics<br />
import qualified Language.Haskell.TH as TH<br />
import Language.Haskell.TH.Quote<br />
<br />
import Expr<br />
</haskell><br />
<br />
= Syntax =<br />
<br />
Our simple expression language consists of integers, the standard operators<br />
+,x,*,/, and parenthesized expressions. We will write a single parser that takes<br />
concrete syntax for this language and transforms it to abstract syntax. Using<br />
the SYB approach to generic programming, we will then use this parser to produce<br />
expression and pattern quasiquoters. Our quasiquoter will allow us to write<br />
<hask>[expr|1 + 3|]</hask> directly in Haskell source code instead of the<br />
corresponding abstract syntax.<br />
<br />
An obvious datatype for the abstract syntax of this simple language is:<br />
<br />
<haskell><br />
data Expr = IntExpr Integer<br />
| BinopExpr (Integer -> Integer -> Integer) Expr Expr<br />
deriving(Show)<br />
</haskell><br />
<br />
Unfortunately, this won't do for our quasiquoter. First of all, the SYB<br />
technique we use cannot handle function types in a generic way, so the BinopExpr<br />
constructor must be modified. SYB also requires that we derive Typeable and<br />
Data, a trivial change. Finally, we want to support antiquoting for two<br />
syntactic categories, expressions and integers. With antiquoting support, we can<br />
write [expr|$x + $int:y|] where x and y are in-scope variables with types Expr<br />
and Integer, respectively. The final data types for our abstract syntax are:<br />
<br />
<haskell><br />
data Expr = IntExpr Integer<br />
| AntiIntExpr String<br />
| BinopExpr BinOp Expr Expr<br />
| AntiExpr String<br />
deriving(Show, Typeable, Data)<br />
<br />
data BinOp = AddOp<br />
| SubOp<br />
| MulOp<br />
| DivOp<br />
deriving(Show, Typeable, Data)<br />
</haskell><br />
<br />
An evaluator for our abstract syntax can be written as follows:<br />
<br />
<haskell><br />
eval :: Expr -> Integer<br />
eval (IntExpr n) = n<br />
eval (BinopExpr op x y) = (opToFun op) (eval x) (eval y)<br />
where<br />
opToFun AddOp = (+)<br />
opToFun SubOp = (-)<br />
opToFun MulOp = (*)<br />
opToFun DivOp = div<br />
</haskell><br />
<br />
= Parsing =<br />
<br />
We use Parsec to write a parser for our expression language. Note that we have<br />
(somewhat arbitrarily) chosen the syntax for antiquotaton to be as in the above<br />
example; a quasiquoter may choose whatever syntax she wishes.<br />
<br />
<haskell><br />
small = lower <|> char '_'<br />
large = upper<br />
idchar = small <|> large <|> digit <|> char '\''<br />
<br />
lexeme p = do{ x <- p; spaces; return x }<br />
symbol name = lexeme (string name)<br />
parens p = between (symbol "(") (symbol ")") p<br />
<br />
expr :: CharParser st Expr<br />
expr = term `chainl1` addop<br />
<br />
term :: CharParser st Expr<br />
term = factor `chainl1` mulop<br />
<br />
factor :: CharParser st Expr<br />
factor = parens expr <|> integer <|> try antiIntExpr <|> antiExpr<br />
<br />
mulop = do{ symbol "*"; return $ BinopExpr MulOp }<br />
<|> do{ symbol "/"; return $ BinopExpr DivOp }<br />
<br />
addop = do{ symbol "+"; return $ BinopExpr AddOp }<br />
<|> do{ symbol "-"; return $ BinopExpr SubOp }<br />
<br />
integer :: CharParser st Expr<br />
integer = lexeme $ do{ ds <- many1 digit ; return $ IntExpr (read ds) }<br />
<br />
ident :: CharParser s String<br />
ident = do{ c <- small; cs <- many idchar; return (c:cs) }<br />
<br />
antiIntExpr = lexeme $ do{ symbol "$int:"; id <- ident; return $ AntiIntExpr id }<br />
antiExpr = lexeme $ do{ symbol "$"; id <- ident; return $ AntiExpr id }<br />
</haskell><br />
<br />
The helper function parseExpr takes a source code position (consisting of a file<br />
name, line and column) and a string and returns a value of type Expr. This<br />
helper function also ensures that we can parse the whole string rather than just<br />
a prefix.<br />
<br />
<haskell><br />
parseExpr :: Monad m => (String, Int, Int) -> String -> m Expr<br />
parseExpr (file, line, col) s =<br />
case runParser p () "" s of<br />
Left err -> fail $ show err<br />
Right e -> return e<br />
where<br />
p = do pos <- getPosition<br />
setPosition $<br />
(flip setSourceName) file $<br />
(flip setSourceLine) line $<br />
(flip setSourceColumn) col $<br />
pos<br />
spaces<br />
e <- expr<br />
eof<br />
return e<br />
</haskell><br />
<br />
= The Quasiquoter =<br />
<br />
Remember, our quasiquoter allows us to write expression in our simple language,<br />
such as [expr|2 * 3|], directly in Haskell source code. This requires that the<br />
variable expr be in-scope when the quasiquote is encountered, and that it is<br />
bound to a value of type Language.Haskell.TH.Quote.QuasiQuoter, which contains<br />
an expression quoter and a pattern quoter. Note that expr must obey the same<br />
stage restrictions as Template Haskell; in particular, it may not be defined in<br />
the same module where it is used as a quasiquoter, but must be imported.<br />
<br />
Our expression and pattern quoters are quoteExprExp and quoteExprPat,<br />
respectively, so our quasiquoter expr is written as follows:<br />
<br />
<haskell><br />
quoteExprExp :: String -> TH.ExpQ<br />
quoteExprPat :: String -> TH.PatQ<br />
<br />
expr :: QuasiQuoter<br />
expr = QuasiQuoter quoteExprExp quoteExprPat<br />
</haskell><br />
<br />
Our quasiquoters re-use the parser we wrote in the previous section, parseExpr,<br />
and make use of the generic functions dataToExpQ and dataToPatQ (described in<br />
the Haskell Workshop paper). These functions, from the Language.Haskell.TH.Quote<br />
package, take a Haskell value and reflect it back into the language as Template<br />
Haskell abstract syntax. The catch is that we don't want to handle all values<br />
generically: antiquoted values must be handled specially. Consider the AntiExpr<br />
constructor; we don't want this constructor to be mapped to Template Haskell<br />
abstract syntax for the AntiExpr constructor, but to abstract syntax for the<br />
Haskell variable named by the constructor's argument. The extQ combinator allows<br />
us to do this nicely by defining a function antiExprExp that handles<br />
antiquotations.<br />
<br />
<haskell><br />
quoteExprExp s = do loc <- TH.location<br />
let pos = (TH.loc_filename loc,<br />
fst (TH.loc_start loc),<br />
snd (TH.loc_start loc))<br />
expr <- parseExpr pos s<br />
dataToExpQ (const Nothing `extQ` antiExprExp) expr<br />
<br />
antiExprExp :: Expr -> Maybe (TH.Q TH.Exp)<br />
antiExprExp (AntiIntExpr v) = Just $ TH.appE (TH.conE (TH.mkName "IntExpr"))<br />
(TH.varE (TH.mkName v))<br />
antiExprExp (AntiExpr v) = Just $ TH.varE (TH.mkName v)<br />
antiExprExp _ = Nothing<br />
</haskell><br />
<br />
The corresponding code for patterns is:<br />
<br />
<haskell><br />
quoteExprPat s = do loc <- TH.location<br />
let pos = (TH.loc_filename loc,<br />
fst (TH.loc_start loc),<br />
snd (TH.loc_start loc))<br />
expr <- parseExpr pos s<br />
dataToPatQ (const Nothing `extQ` antiExprPat) expr<br />
<br />
antiExprPat :: Expr -> Maybe (TH.Q TH.Pat)<br />
antiExprPat (AntiIntExpr v) = Just $ TH.conP (TH.mkName "IntExpr")<br />
[TH.varP (TH.mkName v)]<br />
antiExprPat (AntiExpr v) = Just $ TH.varP (TH.mkName v)<br />
antiExprPat _ = Nothing<br />
</haskell><br />
<br />
= Examples =<br />
<br />
We can now try out a few examples by invoking ghci as follows: <code>ghci -XQuasiQuotes Expr/Quote</code><br />
<br />
<pre><br />
> [expr|1 + 3 + 5|]<br />
BinopExpr AddOp (BinopExpr AddOp (IntExpr 1) (IntExpr 3)) (IntExpr 5) <br />
> eval [expr|1 + 3 + 5|]<br />
9 <br />
</pre><br />
<br />
Taking advantage of our quasiquoter, we can re-write our evaluator so it uses<br />
concrete syntax:<br />
<br />
<haskell><br />
eval' :: Expr -> Integer<br />
eval' [expr|$int:x|] = x<br />
eval' [expr|$x + $y|] = eval' x + eval' y<br />
eval' [expr|$x - $y|] = eval' x - eval' y<br />
eval' [expr|$x * $y|] = eval' x * eval' y<br />
eval' [expr|$x / $y|] = eval' x `div` eval' y<br />
</haskell><br />
<br />
Let's make sure it works as advertised:<br />
<br />
<pre><br />
> eval [expr|1 + 2 + 3|] == eval' [expr|1 + 2 + 3|]<br />
True <br />
> eval [expr|1 + 3 * 5|] == eval' [expr|1 + 3 * 5|]<br />
True <br />
</pre></div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-30T20:17:25Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Case guards===<br />
Cases can have guards and case alternatives in more-declarations can also have guards that use more-notation. There is no guarantee to the order except:<br />
* Guards listed in a single more-declaration keep that order.<br />
* Duplicate guards are removed.<br />
* Duplicate guard conditions that to not have matching result expressions are errors.<br />
* You can list guard conditions without the result values; these cause the order to be forced if such guard conditions exist, but does not create them if they do not exist.<br />
<br />
Example:<br />
y x = case x of {<br />
more Cases;<br />
};<br />
Cases = (a, b) | more X a b;<br />
X a b = a > 5 -> b;<br />
X a b = a < 5 -> a;<br />
X a b = a == 5 -> 0;<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-27T21:46:54Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreMode Name [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreMode<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-27T21:43:03Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* Info<br />
** MoreI Int MoreKind [Dec]<br />
* MoreField = (Name, Maybe StrictType, Maybe Exp)<br />
* MoreKind<br />
** MoreCase<br />
** MoreData<br />
** MoreDo<br />
** MoreList<br />
** MoreRec Bool Bool<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-27T21:38:07Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* MoreField = (Name, StrictType, Exp)<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-27T21:37:43Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===<br />
* Dec<br />
** MoreCaseD Name MoreOrder [Name] [Match]<br />
** MoreDataD Name MoreOrder [Name] [Con]<br />
** MoreDoD Name MoreOrder [Name] [Stmt]<br />
** MoreListD Name MoreOrder [Name] [Exp]<br />
** MoreRecD Name MoreOrder [Name] [MoreField]<br />
* MoreField = (StrictType, Exp)<br />
* MoreOrder<br />
** NoOrder<br />
** NamedOrder Name<br />
** NumericOrder Int</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-27T21:23:40Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
A statement in a do-block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple statements in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
more Doing x;<br />
print x;<br />
};<br />
Doing a = a <- return $ x a;<br />
becomes<br />
x = (2 *);<br />
main = do {<br />
x <- return 21;<br />
x <- return $ Main.x x;<br />
print x; -- results in 42 (the answer to life, the universe, and everything)<br />
};<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
A field in either a data type declaration or in a value construction or update syntax can be replaced by more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate fields are removed.<br />
* Duplicate fields that do not match are errors.<br />
* A more-declaration can specify both the type and the value. Types are only used in data type declarations and values only in the other places.<br />
<br />
Example:<br />
data Abc = Abc { name_of :: String, more AbcField };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", more AbcField };<br />
AbcField = age_of :: Int = 0;<br />
AbcField = existing :: Bool = True;<br />
becomes<br />
data Abc = Abc { name_of :: String, age_of :: Int, existing :: Bool };<br />
makeAbc :: Abc;<br />
makeAbc = Abc { name_of = "", age_of = 0, existing = True }; <br />
<br />
===Lists===<br />
A list item can be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Multiple items in a single more-declaration stay in that order and consecutive.<br />
<br />
Example:<br />
k :: [String];<br />
k = [more K];<br />
1 K = "One";<br />
5 K = "Five";<br />
3 K = "Three";<br />
K = "Zero";<br />
becomes:<br />
k :: [String];<br />
k = ["Zero", "One", "Three", "Five"];<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-27T21:07:50Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero. This number is called the "order" of the declaration.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here. This number is called the "order" of the declaration.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation. An unused parameter can be replaced by an underscore.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
<br />
===Case alternatives===<br />
An alternative for a case block may be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Cases within an order are reordered so that the most specific ones come first.<br />
<br />
Example:<br />
X = (_, False, True) -> 1;<br />
X = (True, True, True) -> 2;<br />
X = _ -> 3;<br />
X = (False, True, True) -> 4;<br />
y x = case x of {<br />
more X;<br />
};<br />
becomes:<br />
y x = case x of {<br />
(True, True, True) -> 2;<br />
(False, True, True) -> 4;<br />
(_, False, True) -> 1;<br />
_ -> 3;<br />
};<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
<br />
===Lists===<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-27T20:47:56Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
* ''numeric_literal'': It should be a natural number. Omitted is the same as zero.<br />
* ''enumeration_constructor'': A constructor of the enumeration that was specified in the more-notation. If an enumeration is specified, the enumeration constructor is required here.<br />
* ''parameters'': Lowercased names which will be scoped locally to this declaration. The number of parameters must match the number of parameters specified in the more-notation.<br />
* ''contents'': The contents depends on where the more-notation is.<br />
<br />
==Semantics==<br />
In the place where the more-notation is, all contents of more-declarations of that name will be reordered and corrected before being placed in place of the more-notation.<br />
<br />
Automatic reordering is overridden by the enumeration constructors or numeric literals in front of more-declarations.<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
<br />
===Case alternatives===<br />
<br />
===Datatype declarations===<br />
A constructor definition in a data declaration is allowed to be replaced by a more-notation. Semantics of more-declarations becomes as follows:<br />
* Duplicate constructors are removed.<br />
* Duplicate constructors that do not match are errors.<br />
* Multiple constructors in a single more-declaration are guaranteed to keep the order given.<br />
<br />
Example:<br />
data T = Zero | more T deriving (Eq);<br />
T = Two | Three | Four;<br />
T = One | Two;<br />
becomes<br />
data T = Zero | One | Two | Three | Four deriving (Eq);<br />
<br />
===Fields in record syntax===<br />
<br />
===Lists===<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===<br />
<br />
===Types and constructors===</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-27T20:33:11Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
<br />
==Semantics==<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
<br />
===Case alternatives===<br />
<br />
===Datatype declarations===<br />
<br />
===Fields in record syntax===<br />
<br />
===Lists===<br />
<br />
==Combining with Template Haskell==<br />
<br />
===Uses in quotations===<br />
<br />
===Manipulation in splices===</div>Zzo38https://wiki.haskell.org/User:Zzo38/Proposal_for_more-notationUser:Zzo38/Proposal for more-notation2011-08-27T20:29:02Z<p>Zzo38: </p>
<hr />
<div>This document is proposal for more-notation in Haskell.<br />
<br />
==Syntax==<br />
Anywhere that a more-notation is allowed (see Uses), you can use the syntax:<br />
* <tt>more</tt> ''[''<tt>(</tt>''name_of_enumeration''<tt>)</tt>'']'' ''more_name'' ''{parameters}''<br />
* ''name_of_enumeration'': A name of any type which is an enumeration. It can be another one using more-notation, but it must be able to fully determine it before this more-notation can be fully determined.<br />
* ''more_name'': A capitalized name. It uses the same namespace as constructors, so you are not allowed to have a constructor of the same name (although it is OK to have types of the that name).<br />
* ''parameters'': Optional lowercased names. These names are in local scope, and may already exist in this scope, although they do not have to.<br />
<br />
A more-declaration is a module-level declaration of this syntax:<br />
* ''['' ''numeric_literal'' ''|'' <tt>(</tt>''enumeration_constructor''<tt>)</tt> '']'' ''more_name'' ''{parameters}'' <tt>=</tt> ''contents'' ''{'' <tt>|</tt> ''contents'' ''}'' <tt>;</tt><br />
<br />
==Semantics==<br />
<br />
==Uses==<br />
<br />
===Do-blocks===<br />
<br />
===Case alternatives===<br />
<br />
===Datatype declarations===<br />
<br />
===Fields in record syntax===<br />
<br />
===Lists===<br />
<br />
==Combining with Template Haskell==</div>Zzo38