Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
F Sharp (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Agent programming=== F# supports a variation of the [[Actor model|actor]] programming model through the in-memory implementation of lightweight asynchronous agents. For example, the following code defines an agent and posts 2 messages: <syntaxhighlight lang="fsharp"> type Message = | Enqueue of string | Dequeue of AsyncReplyChannel<Option<string>> // Provides concurrent access to a list of strings let listManager = MailboxProcessor.Start(fun inbox -> let rec messageLoop list = async { let! msg = inbox.Receive() match msg with | Enqueue item -> return! messageLoop (item :: list) | Dequeue replyChannel -> match list with | [] -> replyChannel.Reply None return! messageLoop list | head :: tail -> replyChannel.Reply (Some head) return! messageLoop tail } // Start the loop with an empty list messageLoop [] ) // Usage async { // Enqueue some strings listManager.Post(Enqueue "Hello") listManager.Post(Enqueue "World") // Dequeue and process the strings let! str = listManager.PostAndAsyncReply(Dequeue) str |> Option.iter (printfn "Dequeued: %s") } |> Async.Start </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)