operate-do: Simple project template from stack

[ library, meta, mit ] [ Propose Tags ] [ Report a vulnerability ]

Please see README.md


[Skip to Readme]

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

Candidates

Versions [RSS] 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 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:56:44Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 878 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-11-17 [all 1 reports]

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