MyNixOS website logo
Description

Simple project template from stack.

Please see README.md

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
Metadata

Version

0.1.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows