לדלג לתוכן

קובץ:Understanding arrows getWord data flow.svg

תוכן הדף אינו נתמך בשפות אחרות.
מתוך ויקיפדיה, האנציקלופדיה החופשית

לקובץ המקורי(קובץ SVG, הגודל המקורי: 1,000 × 1,936 פיקסלים, גודל הקובץ: 35 ק"ב)

ויקישיתוף זהו קובץ שמקורו במיזם ויקישיתוף. תיאורו בדף תיאור הקובץ המקורי (בעברית) מוצג למטה.

תקציר

תיאור
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
תאריך יצירה
מקור נוצר על־ידי מעלה היצירה
יוצר 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

רישיון

אני, בעל זכויות היוצרים על עבודה זו, מפרסם בזאת את העבודה תחת הרישיון הבא:
w:he:Creative Commons
ייחוס שיתוף זהה
הקובץ הזה מתפרסם לפי תנאי רישיון קריאייטיב קומונז ייחוס-שיתוף זהה 4.0 בין־לאומי.
הנכם רשאים:
  • לשתף – להעתיק, להפיץ ולהעביר את העבודה
  • לערבב בין עבודות – להתאים את העבודה
תחת התנאים הבאים:
  • ייחוס – יש לתת ייחוס הולם, לתת קישור לרישיון, ולציין אם נעשו שינויים. אפשר לעשות את זה בכל צורה סבירה, אבל לא בשום צורה שמשתמע ממנה שמעניק הרישיון תומך בך או בשימוש שלך.
  • שיתוף זהה – אם תיצרו רמיקס, תשנו, או תבנו על החומר, חובה עליכם להפיץ את התרומות שלך לפי תנאי רישיון זהה או תואם למקור.

כיתובים

נא להוסיף משפט שמסביר מה הקובץ מייצג

פריטים שמוצגים בקובץ הזה

מוצג

היסטוריית הקובץ

ניתן ללחוץ על תאריך/שעה כדי לראות את הקובץ כפי שנראה באותו זמן.

תאריך/שעהתמונה ממוזערתממדיםמשתמשהערה
נוכחית07:26, 17 ביולי 2015תמונה ממוזערת לגרסה מ־07:26, 17 ביולי 2015‪1,936 × 1,000‬ (35 ק"ב)DuplodeUser created page with UploadWizard

אין בוויקיפדיה דפים המשתמשים בקובץ זה.

שימוש גלובלי בקובץ

אתרי הוויקי השונים הבאים משתמשים בקובץ זה:

מטא־נתונים