(* This file is simply the “tangled” F# code of ruby-f#-demo.org; it is the “raw” source code, provided for your convenience. *) let x, y = 5, 10 printfn "%b" (x > y) printfn "%b" (x < y) printfn "%b" (x = y) let x, y = 5, 10 let printbool = (printfn "%b") printbool (x < y) printbool (x = y) let x = printfn "Hello world" printfn "%O" x printfn "hello" if 2 = 5 then printfn "What reality am I in?" if 2 = 7 then printfn "Now I'm even more concerned..." elif 2 = 4 then printfn "This doesn't help either..." else printfn "Okay, maybe everything's okay." let r = match 5 with | 0 -> "Factorial is 1." | 1 -> "Factorial is 1." | 2 -> "Factorial is 2." | 3 -> "Factorial is 6." | 4 -> "Factorial is 24." | _ -> "I'm tired, go away." printfn "%s" r let r = match 5 with | 5 when false -> "It might match, but it can't satisfy this guard!" | 5 when true -> "This guard's easily pleased." | _ -> "Uh... hello?" printfn "%s" r let rec fact n = match n with | 0 -> 1 | n when n > 0 -> n * fact (n - 1) | _ -> printfn "Can't calculate factorial of a negative!" -1 printfn "Factorial 5 is %d" (fact 5) let rec forever (x : int) : int = printfn "All work and no play makes F# a dull language..." forever x let rec forever' (_ : unit) : Lazy = printfn "I can do it, I can do it ∞ times!" forever'() let forever : Lazy = lazy while true do printfn "Much better..." for x in [1;2;3] do printfn "Iterating through a list %d" x for x = 1 to 3 do printfn "Counting up %d" x for x = 3 downto 1 do printfn "Counting down %d" x let value = System.Console.ReadLine() System.Console.WriteLine("Is there an echo in here?"); System.Console.WriteLine(value) let rec forever : Lazy = let rec forever_helper (so_far : sbyte) : sbyte = match so_far with | 0y -> printfn "Starting out..." forever_helper 1y | n when n % 100y = 0y -> printfn "Took a hundred steps..." forever_helper (n + 1y) | n when n = -1y -> printfn "Sorry, fell asleep and overflowed a bit!" forever_helper (n + 1y) | n -> forever_helper (n + 1y) in lazy forever_helper 0y