This file contains hidden or 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
| let rec fibf = Seq.cache <| seq { | |
| yield! [1I; 1I] | |
| yield! Seq.map2 (+) fibf (Seq.skip 1 fibf) | |
| };; | |
| fibf |> Seq.nth 100000 |
This file contains hidden or 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
| let getPrimeFactors n = | |
| let allFactors = seq { yield 2; yield! Seq.initInfinite (fun i -> 2 * i + 3) } |> Seq.cache | |
| let addFactor factors d = | |
| match Map.tryFind d factors with | |
| | None -> Map.add d 1 factors | |
| | Some count -> Map.remove d factors |> Map.add d (count + 1) | |
| let rec gPF n factors = | |
| allFactors | |
| |> Seq.takeWhile (fun d -> d <= (n |> float |> sqrt |> int)) | |
| |> Seq.tryFind (fun d -> n % d = 0) |
This file contains hidden or 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 | |
| type IParallelLimiter = | |
| abstract GetToken : unit -> Async<IDisposable> | |
| type Message= | |
| | GetToken of AsyncReplyChannel<IDisposable> | |
| | Release | |
| let start count = |
This file contains hidden or 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
| let (|Negative|Positive|Zero|) x = | |
| if x > 0 then Positive | |
| else if x < 0 then Negative | |
| else Zero | |
| let count = -2;; | |
| match count with | |
| | Zero | Negative -> printfn "Zero or less" | |
| | Positive -> printfn "Greater than zero" |
This file contains hidden or 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 | |
| open System.IO | |
| open System.Net | |
| type Request = Request of WebRequest * AsyncReplyChannel<WebResponse> | |
| let requestAgent = | |
| MailboxProcessor.Start <| fun inbox -> async { | |
| while true do | |
| let! (Request (req, port)) = inbox.Receive () |
This file contains hidden or 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
| let fn () = failwith "Test";; | |
| async { | |
| try | |
| fn () | |
| with e -> printfn "Catched %A" e | |
| } |> Async.RunSynchronously |
This file contains hidden or 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
| let (|Equals|_|) x y = | |
| if x = y then Some () else None | |
| let (|Id|_|) f x = | |
| if f x then Some () else None | |
| let a = 3;; | |
| match 3 with | |
| | Equals a -> "Yes" |
This file contains hidden or 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
| type Status = Active | Standby | Inactive | |
| let status = Active | |
| let isOnline = true | |
| if not isOnline then | |
| printfn "Status is offline or inactive" | |
| else | |
| match status with | |
| | Active -> "Status is active" |
This file contains hidden or 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
| #r "System.Windows.Forms" | |
| open System.Windows.Forms | |
| let form = new Form (Visible = true, TopMost = true) | |
| let button = new Button() | |
| form.Controls.Add button | |
| button.Click.Add <| (fun _ -> MessageBox.Show "Hello" |> ignore) |
This file contains hidden or 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
| type MessageWithResponse = | |
| | GetNextNumber of AsyncReplyChannel<int> * int | |
| let inbox = | |
| MailboxProcessor.Start <| fun inbox -> | |
| async { | |
| while true do | |
| let! (GetNextNumber(channel, num)) = inbox.Receive() | |
| channel.Reply (num + 1) | |
| };; |