The operate-do package

[Tags:library, mit, test]

Please see README.md


[Skip to Readme]

Properties

Versions 0.1.0
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 repository head: git clone git+https://gitlab.mma.club.uec.ac.jp/uecmma/haskell-library-collections.git
Uploaded Wed Nov 9 09:56:44 UTC 2016 by mizunashi_mana
Distributions NixOS:0.1.0
Downloads 59 total (11 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2016-11-17 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Flags

NameDescriptionDefaultType
test-doctestEnabledManual

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

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for operate-do

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