operate-do: Simple project template from stack

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see README.md


[Skip to Readme]

Properties

Versions 0.1.0, 0.1.0
Change log None available
Dependencies base (>=4.7 && <5), charset, haskell-src-meta (>=0.2), template-haskell (>=2.11 && <3) [details]
License MIT
Copyright 2016 uecmma
Author uecmma
Maintainer developer@mma.club.uec.ac.jp
Category Meta
Home page https://github.com/uecmma/haskell-library-collections/tree/master/operate-do
Bug tracker https://github.com/uecmma/haskell-library-collections/issues
Source repo head: git clone git+https://gitlab.mma.club.uec.ac.jp/uecmma/haskell-library-collections.git
Uploaded by mizunashi_mana at 2016-11-09T09:49:00Z

Modules

[Index]

Flags

Manual Flags

NameDescriptionDefault
test-doctestEnabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for operate-do-0.1.0

[back to package description]

Operate Do

This packages provides an useful syntax sugar for infixing.

Usage

-- Same as `pure const <*> Just 1 <*> Just 2 == Just 1`
[opdo| <*> ->
  pure const
  Just 1
  Just 2
  |]

The reason why

When we make complexible program, we use many brackets:

dataParser = ComplexData
  <$> (takeWhile1 isToken <* char8 ' ')
  <*> (takeWhile1 (/= 32) <* char8 ' ')
  <*> (some <* endOfLine)

Operate do provides non-use brackets interface:

-- Or `[opdo| <*> -> { pure ComplexData; ... } |]`
[opdo| <*> ->
  pure ComplexData
  takeWhile1 isToken <* char8 ' '
  takeWhile1 (/= 32) <* char8 ' '
  some <* endOfLine
  |]

Of course, you can free to use $. Moreover, this is used as weak do:

-- Same `do { putStrLn "Hello"; putStrLn "World" }`
[opdo| >> ->
  putStrLn "Hello"
  putStrLn "World"
  |]

Syntax

<operate do>     ::= [opdo| <opdooperator> -> { <opdostatements> <expression> [;] }]
<opdooperator>   ::= <identifer>
                   | ( <identifer> )
<opdostatements> ::= <opdostatements> <opdostatement>
                   |
<opdostatement>  ::= <expression> ;
                   | ;

An example:

[opdo| >>> -> { (+ 1); show; head } |] :: Num a => a -> Char

# Same (use section version)
[opdo| (>>>) -> { (+ 1); show; head } |]

Allow multiline statement same as do notation:

[opdo| >>> ->
  (+ 1)
  show
  head
|]

# Same (brackets multiline)
[opdo| >>> -> {
  (+ 1);
  show;
  head;
}|]

This is not supported from some reason:

# This is compile error!
[opdo| >>> -> (+ 1)
              show
              head
|]

Translation

For operation

Taking associativity into consideration:

[opdo| op -> a; b; c |] == a op b op c

For function

Take left associativity:

[opdo| func -> a; b; c |] == a `func` b `func` c