This is a file from the Wikimedia Commons

File:Understanding arrows mean1 data flow.svg

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Original file(SVG file, nominally 1,000 × 436 pixels, file size: 17 KB)

Summary

Description
English: Data flow in the mean1 example of b:en:Haskell/Arrow tutorial. Rectangles are arrows (rounded rectangles are arrows made with arr) and circles are other data flow split/merge points. Haskell source code being represented:
(total &&& (const 1 ^>> total)) >>> arr (uncurry (/))
Date
Source Own work
Author Daniel Mlot

Haskell/diagrams source code for generating the image:

{-# LANGUAGE NoMonomorphismRestriction #-}

import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine

main = mainWith $ pad 1.05 . centerXY $ connDiag

baseDiag = hsep 0.5 . fmap centerY $
    [ anAmper # named "amp"
    , anArrow "total" # named "sum" # centerX
        ===
    strutY 1
        ===
    (aFunction "const 1" # named "one" |||
        strutX 1 |||
        anArrow "total" # named "count") # named "path2" # centerX
    , aFunction "/" # named "divide"
    ]

connDiag = baseDiag
    # connectPerim' baseConnOpts
        "amp" "sum" (1/8 @@ turn) (1/2 @@ turn)
    # connectPerim' baseConnOpts
        "amp" "one" (7/8 @@ turn) (1/2 @@ turn)
    # connectPerim' baseConnOpts
        "one" "count" (0 @@ turn) (1/2 @@ turn)
    # connectPerim' baseConnOpts
        "sum" "divide" (0 @@ turn) (3/8 @@ turn)
    # connectPerim' baseConnOpts
        "count" "divide" (0 @@ turn) (5/8 @@ turn)
    where
    baseConnOpts = with & lengths .~ large
        & shaftStyle %~ lc baseColour . lw veryThick
        & headStyle %~ fc (darken 0.2 baseColour)

aFunction :: String -> Diagram B
aFunction s = roundedRect 1.6 1.2 0.4 # applyStyle initStyle
    <> nudgedText s
        # fc baseColour

anArrow :: String -> Diagram B
anArrow s = rect 1.6 1.2 # applyStyle initStyle
    <> nudgedText s

anAmper :: Diagram B
anAmper = circle 0.5 # applyStyle initStyle
    <> nudgedText "&&&"

initStyle :: Style V2 Double
initStyle = mempty # lc baseColour # lwL 0.1

baseColour = mediumorchid

nudgedText :: String -> Diagram B
nudgedText s = alignedText 0.5 0.5 s
    # font "monospace" # fontSize (local 0.25) # bold # fc baseColour

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

16 July 2015

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current00:22, 17 July 2015Thumbnail for version as of 00:22, 17 July 20151,000 × 436 (17 KB)DuplodeUser created page with UploadWizard

The following 2 pages use this file:

Metadata