needle-0.1.0.1: ASCII-fied arrow notation

Copyright(c) 2014 Josh Kirklin
LicenseMIT
Maintainerjjvk2@cam.ac.uk
Safe HaskellNone
LanguageHaskell2010

Control.Arrow.Needle

Contents

Description

Needle is a domain specific language for ASCII-fied arrow notation. This module enables the use of needle within Haskell by making use of Template Haskell.

In needle, data travels along rails. There are three types of rail, and data travels in different directions on each:

=
left to right
\
down
/
up

Data enters a rail with }, and exits with >.

When rails are joined, their contents are concatenated. When rails are split, their contents are duplicated.

An external arrow can be embedded in a rail by enclosing it between a { and a }.

Inputs and outputs of rails can be asigned labels with a :.

Rails can cross one another, if one of the rails has gone 'underground' by entering a 'tunnel'. A tunnel entrance is specified by a ), and a tunnel exit is specified by a (.

Most questions should be answered by a short example:

import Control.Arrow.Needle

nTest :: (Int, Int, Int) -> (Int, (Int, Int, Int))
nTest = [nd|
                        aLabel:==={div 2}===\
    }====\                                  \
         {uncurry (+)}==\=================) \ (==>
    }====/              \                   \
                        \                   \=={nTriple}=>
                        \               
                     }=={uncurry (-)}====:aLabel
|]

nTriple = [nd|
    }==\==>
       \==>
       \==>
|]
>>> nTest (3,2,1)
(5,(-1,-1,-1))

Synopsis

Documentation

nd :: QuasiQuoter Source

The inline needle quasi-quoter.

{-# LANGUAGE QuasiQuotes #-}

exampleArrow :: Num c => (a,b,c) -> (a,a,b,c,c)
exampleArrow = [nd|
   }===========>
      \========>
   }===========>
   }==={negate}>
      \========>
 |]

ndFile :: FilePath -> ExpQ Source

Load a needle from a file.

{-# LANGUAGE TemplateHaskell #-}

exampleArrow :: Float -> Float
exampleArrow = $(ndFile "example.nd")

Reexported for your convenience