File:Understanding arrows getWord data flow.svg
From Wikimedia Commons, the free media repository
Jump to navigation
Jump to search
Size of this PNG preview of this SVG file: 309 × 598 pixels. Other resolutions: 124 × 240 pixels | 248 × 480 pixels | 396 × 768 pixels | 529 × 1,024 pixels | 1,058 × 2,048 pixels | 1,000 × 1,936 pixels.
Original file (SVG file, nominally 1,000 × 1,936 pixels, file size: 35 KB)
File information
Structured data
Captions
Summary
[edit]DescriptionUnderstanding arrows getWord data flow.svg |
English: Data flow in a fragment of the getWord 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. Blue indicates a Left tag, red indicates Right and purple indicates lack of Either tags. Corresponding code:proc () -> do
firstTime <- oneShot -< ()
mPicked <- if firstTime
then do
picked <- pickWord rng -< ()
returnA -< Just picked
else returnA -< Nothing
accum' Nothing mplus -< mPicked
|
Date | |
Source | Own work |
Author | Daniel Mlot |
Haskell/diagrams code for generating the image:
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE LambdaCase #-}
import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine
main = mainWith $ pad 1.05 . centerXY $ getWordDiagV
getWordDiagV =
[ vsep 1
[ anArrow Ne "accum' Nothing mplus" # named "accum"
, aFork Ne "|||" # named "merge"
]
, vsep 1
[ aFunction Le "Just" # named "just"
, anArrow Le "pickWord rng" # named "pickWord"
, aFunction Le "const ()" # named "unit"
] # centerY
|||
strutX 1
|||
aFunction Ri "const Nothing" # named "nothing" # centerY
, vsep 1
[ aFork Ne "if" # named "if"
, anArrow Ne "oneShot" # named "oneShot"
]
] # fmap centerX # vsep 0.5
# connectNodes Ne "oneShot" "if" (1/4) (3/4)
# connectNodes Le "if" "unit" (3/8) (7/8)
# connectNodes Le "unit" "pickWord" (1/4) (3/4)
# connectNodes Le "pickWord" "just" (1/4) (3/4)
# connectNodes Le "just" "merge" (1/8) (5/8)
# connectNodes Ri "if" "nothing" (1/8) (5/8)
# connectNodes Ri "nothing" "merge" (3/8) (7/8)
# connectNodes Le "merge" "accum" (1/4) (3/4)
data ForkFlag = Le | Ne | Ri
forkColour :: ForkFlag -> Colour Double
forkColour = \case
Le -> blue
Ne -> mediumorchid
Ri -> red
connectNodes :: ForkFlag -> String -> String
-> Double -> Double -> Diagram B -> Diagram B
connectNodes ffl nam1 nam2 tur1 tur2 =
connectPerim' (baseConnOpts ffl)
nam1 nam2 (tur1 @@ turn) (tur2 @@ turn)
baseConnOpts ffl = with & lengths .~ large
& shaftStyle %~ lc colo . lw veryThick
& headStyle %~ fc (darken 0.2 colo)
where
colo = forkColour ffl
nodeSkeleton :: Diagram B -> ForkFlag -> String -> Diagram B
nodeSkeleton d ffl s = d # scaleX (max 1 $ fromIntegral (length s) / 7)
# applyStyle initStyle # lc colo
<> nudgedText s
# fc colo
where
colo = forkColour ffl
aFunction :: ForkFlag -> String -> Diagram B
aFunction = nodeSkeleton $ roundedRect 1.6 1.2 0.4
anArrow :: ForkFlag -> String -> Diagram B
anArrow = nodeSkeleton $ rect 1.6 1.2
aFork :: ForkFlag -> String -> Diagram B
aFork = nodeSkeleton $ circle 0.5
initStyle :: Style V2 Double
initStyle = mempty # lwL 0.1
nudgedText :: String -> Diagram B
nudgedText s = alignedText 0.5 0.5 s
# font "monospace" # fontSize (local 0.25) # bold
Licensing
[edit]I, the copyright holder of this work, hereby publish it under the following license:
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.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 04:26, 17 July 2015 | 1,000 × 1,936 (35 KB) | Duplode (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
File usage on other wikis
The following other wikis use this file:
- Usage on en.wikibooks.org
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Width | 800pt |
---|---|
Height | 1548.93617pt |
Hidden categories: