Ur/Web Examples
Check-in [c4437d6ed0]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:make composableSignals demo interactive to better illustrate the benefits of signal lifting
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c4437d6ed04a1f86ee753f0c1c28e12cf7986038
User & Date: beyert 2016-08-17 05:59:34
Context
2016-08-17
07:23
in composableSignals, use better examples / make examples more consistent, particuarly showing that pure/return can be used as a constructor for signals check-in: 904ba75c5b user: beyert tags: trunk
05:59
make composableSignals demo interactive to better illustrate the benefits of signal lifting check-in: c4437d6ed0 user: beyert tags: trunk
05:40
add liftS3 / liftS3' to composableSignals library, with examples provided check-in: 7a264a41b0 user: beyert tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to composableSignals/composableSignals.ur.

52
53
54
55
56
57
58

















59
60
61
62
63
64
65
66
..
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  srcX <- source (3: int);
  srcY <- source (2: int);

  return <xml><head>
    <title>Test of map and lifted signals</title>
    </head>
    <body>

















      <h2>part one</h2>
      <dyn signal={s' <- mapS' (fn x => y <- x; pure (y + 1)) (s srcN);
                   return <xml>{[s']}</xml>}/>
      <dyn signal={s' <- liftS' (fn x => y <- x; pure (y + 1)) (s srcN);
                   return <xml>{[s']}</xml>}/>
      <dyn signal={x' <- liftS2' (fn sx sy => x <- sx; y <- sy; pure (x + y))
                                 (s srcX) (s srcY);
                   return <xml>{[x']}</xml>}/>
................................................................................
                   return <xml>{[x']}</xml>}/>
      <dyn signal={x' <- liftS3' (fn sx sy sz => x <- sx; y <- sy; z <- sz;
                                   pure (x * y * z)) (s srcX) (s srcY)
                                 (s srcN);
                   return <xml>{[x']}</xml>}/>
      <dyn signal={s' <- liftS' (fn x => y <- x; pure (y + 1)) (s srcN);
                   return <xml>{[s']}</xml>}/>
      <h2>part two</h2>
      <dyn signal={w' <- liftS2 (fn x y => x * y) (s srcX) (s srcY);
                   x' <- liftS (fn x => x * 2) (pure w');
                   y' <- liftS3 (fn x y z => x * y * z)
                                (pure w') (s srcX) (pure x');
                   z' <- liftS (fn x => x + 11) (pure y');
                   return <xml>{[w']} {[x']} {[y']} {[z']}</xml>}/>
      <dyn signal={s' <- liftS (fn x => x + 1) (s srcN);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







 







|







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  srcX <- source (3: int);
  srcY <- source (2: int);

  return <xml><head>
    <title>Test of map and lifted signals</title>
    </head>
    <body>
      <h2>source values</h2>
      <dyn signal={ n <- s srcN; x <- s srcX; y <- s srcY;
                    return <xml>N = {[n]}, X = {[x]}, Y = {[y]}</xml>}/>
      <br/>
      <button value="Increment N" onclick={fn _ => n <- get srcN;
                                                   set srcN (n + 1)}/>
      <button value="Decrement N" onclick={fn _ => n <- get srcN;
                                                   set srcN (n - 1)}/>
      <button value="Increment X" onclick={fn _ => x <- get srcX;
                                                   set srcX (x + 1)}/>
      <button value="Decrement X" onclick={fn _ => x <- get srcX;
                                                   set srcX (x - 1)}/>
      <button value="Increment Y" onclick={fn _ => y <- get srcY;
                                                   set srcY (y + 1)}/>
      <button value="Decrement Y" onclick={fn _ => y <- get srcY;
                                                   set srcY (y - 1)}/>

      <h2>signal values: part one</h2>
      <dyn signal={s' <- mapS' (fn x => y <- x; pure (y + 1)) (s srcN);
                   return <xml>{[s']}</xml>}/>
      <dyn signal={s' <- liftS' (fn x => y <- x; pure (y + 1)) (s srcN);
                   return <xml>{[s']}</xml>}/>
      <dyn signal={x' <- liftS2' (fn sx sy => x <- sx; y <- sy; pure (x + y))
                                 (s srcX) (s srcY);
                   return <xml>{[x']}</xml>}/>
................................................................................
                   return <xml>{[x']}</xml>}/>
      <dyn signal={x' <- liftS3' (fn sx sy sz => x <- sx; y <- sy; z <- sz;
                                   pure (x * y * z)) (s srcX) (s srcY)
                                 (s srcN);
                   return <xml>{[x']}</xml>}/>
      <dyn signal={s' <- liftS' (fn x => y <- x; pure (y + 1)) (s srcN);
                   return <xml>{[s']}</xml>}/>
      <h2>signal values: part two</h2>
      <dyn signal={w' <- liftS2 (fn x y => x * y) (s srcX) (s srcY);
                   x' <- liftS (fn x => x * 2) (pure w');
                   y' <- liftS3 (fn x y z => x * y * z)
                                (pure w') (s srcX) (pure x');
                   z' <- liftS (fn x => x + 11) (pure y');
                   return <xml>{[w']} {[x']} {[y']} {[z']}</xml>}/>
      <dyn signal={s' <- liftS (fn x => x + 1) (s srcN);