Created
May 10, 2021 12:05
-
-
Save adam-nathan/eddb6ee76be0bb5d00e5187627911a96 to your computer and use it in GitHub Desktop.
Call-by-name semantics in F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let rnd = Random() | |
let randint<'a> = | |
print "generating random number" | |
rnd.Next(0,10) | |
type Signal = Signal with | |
member __.Return x = x | |
member __.Delay (f:unit -> _) = f | |
let a = Signal { return randint } | |
let b = Signal { return randint } | |
let c = Signal { return a() + b() } | |
[for _ in 1..10 -> c ()] // [6; 12; 6; 14; 9; 12; 1; 10; 16; 8] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment