Logistic Map definition
let logistic a x0 = Seq.unfold (fun xn -> Some(xn, a * xn * (1.0 - xn))) x0For low a, the sequence is converging to a fixed point
| C:\tim\temp>type temp.fs | |
| namespace Tim | |
| type SomeClass() = | |
| member private t.Impl _ _ = () | |
| type SomeRecord = { | |
| Inner : SomeClass | |
| } with | |
| member t.Generate arg = |
| type OptionMonad = | OptionMonad with | |
| static member ret x = Some x | |
| static member bind (x, f) = Option.bind f x | |
| type ListMonad = | ListMonad with | |
| static member ret x = [x] | |
| static member bind (x, f) = List.collect f x | |
| let inline ret (monad : ^M) (x : 'a) : 'b = | |
| (^M : (static member ret : 'a -> 'b) (x)) |
| let ಠ_ಠ () = printfn "ಠ_ಠ" | |
| ಠ_ಠ () |
| module Utils = | |
| let updateWith | |
| (localKey : 'Local -> 'Key) | |
| (remoteKey : 'Remote -> 'Key) | |
| (add : 'State -> 'Local -> 'State) | |
| (update : 'State -> 'Local -> 'Remote -> 'State) | |
| (delete : 'State -> 'Remote -> 'State) | |
| (state : 'State) | |
| (local : #seq<'Local>) |
| // Run this as: fsi --use:it.fsx --quiet | |
| open System | |
| open System.Reflection | |
| open Microsoft.FSharp.Compiler.Interactive | |
| let (getSavedItType : unit -> Type, getSavedIt : unit -> obj) = | |
| let t = typeof<IEventLoop> | |
| let t = t.Assembly.GetType(t.Namespace + ".RuntimeHelpers", true) | |
| let bf = BindingFlags.Static ||| BindingFlags.NonPublic | |
| let itTypeMethod = t.GetMethod(name = "GetSavedItType", bindingAttr = bf) |
| open System | |
| open System.Collections.Generic | |
| type IKey = | |
| interface end | |
| type IKey<'Value> = | |
| inherit IKey | |
| [<AbstractClass>] |
| let rec fact acc = | |
| function | |
| | 1 -> acc | |
| | n -> fact (acc * n) (n - 1) | |
| assert fact 1 6 == 720 |
A Unicode maze, inspired by 10 PRINT CHR$ (205.5 + RND (1)); : GOTO 10.
open System
let r = Random() in for j in 1 .. 25 do Console.WriteLine (String([| for i in 1 .. 80 -> char (0x2571 + r.Next(0, 2)) |]))// Output
| module Program | |
| // Copy and paste from the FSharp.Core source code | |
| let inline zeroCreateUnchecked (count:int) = | |
| (# "newarr !0" type ('T) count : 'T array #) | |
| let inline map fn a = | |
| let b = zeroCreateUnchecked (Array.length a) | |
| for i in 0 .. Array.length a - 1 do | |
| b.[i] <- fn a.[i] |