Last active
September 2, 2021 21:45
-
-
Save Szer/3465245cc643dfb87600d7856d641ca7 to your computer and use it in GitHub Desktop.
Mutable Dictionary DSL
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.Collections.Generic | |
| [<Struct>] | |
| type DictBuilder<'a, 'b when 'a: equality> = | |
| val d: Dictionary<'a,'b> | |
| new(()) = { d = Dictionary<'a, 'b>() } | |
| member this.Yield (key, value) = | |
| this.d.Add(key, value) | |
| member this.Zero() = this.d | |
| member _.Combine(_, _) = () | |
| member _.Delay f = f() | |
| member this.Run _ = this.d | |
| let mutDict<'a,'b when 'a: equality> = DictBuilder<'a, 'b>(()) | |
| let a = | |
| mutDict { | |
| 1,3 | |
| 2,4 | |
| 3,5 | |
| } | |
| val a : Dictionary<int,int> = dict [(1, 3); (2, 4); (3, 5)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment