The operate-do package

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]

Please see README.md


[Skip to ReadMe]

Properties

Versions0.1.0, 0.1.0
Change logNone available
Dependenciesbase (>=4.7 && <5), charset, haskell-src-meta (>=0.2), template-haskell (>=2.11 && <3) [details]
LicenseMIT
Copyright2016 uecmma
Authoruecmma
Maintainerdeveloper@mma.club.uec.ac.jp
CategoryMeta
Home pagehttps://github.com/uecmma/haskell-library-collections/tree/master/operate-do
Bug trackerhttps://github.com/uecmma/haskell-library-collections/issues
Source repositoryhead: git clone git+https://gitlab.mma.club.uec.ac.jp/uecmma/haskell-library-collections.git
UploadedWed Nov 9 09:49:00 UTC 2016 by mizunashi_mana

Modules

[Index]

Flags

NameDescriptionDefaultType
test-doctestEnabledManual

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

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for operate-do-0.1.0

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