needle- ASCII-fied arrow notation

Copyright(c) 2014 Josh Kirklin
Safe HaskellNone




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

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)



nd :: QuasiQuoter Source

The inline needle quasi-quoter.

{-# LANGUAGE QuasiQuotes #-}

exampleArrow :: Num c => (a,b,c) -> (a,a,b,c,c)
exampleArrow = [nd|

ndFile :: FilePath -> ExpQ Source

Load a needle from a file.

{-# LANGUAGE TemplateHaskell #-}

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

Reexported for your convenience