将复杂的Map数据结构转换为F# [英] Converting complex Map data structure to F#
本文介绍了将复杂的Map数据结构转换为F#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对F#语言非常陌生,更不用说功能编程了,我在实现Map数据结构时遇到了麻烦。此Map的C#类型等效项为:
I am pretty new to the language F#, let alone functional programming, and I am having trouble implementing a Map data structure. The C# type equivalent of this Map would be:
var map = new Dictionary<int, Dictionary<int, Tuple<char, Tuple<int, int>[]>[]>>();
我试图自己实现并在线搜索,但是我对这种语言的缺乏经验让我
I've tried to implement this myself and searching online, but my inexperience with the language is letting me down.
有人能给我看吗?
- 一个不变的实现这种结构
- 可变的实现
推荐答案
对于这样的示例:
let t1 = (2,3)
let t2 = ("a",t1)
let m1 = Map([1,t2])
let m2 = Map([2,m1])
此签名为:
val it : Map<int,Map<int,(string * (int * int))>> = map [(2, map [(1, ("a", (2, 3)))])]
这是使用列表而不是数组。
This is using lists not array.
对于可变部分,您已经显示了实现。只需使用
For the mutable part you already show the implementation. Just use
System.Collections.Generic.Dictionary
不确定,但这也许对您有帮助: F#映射到C#字典
Not sure but maybe this is helpful for you: F# map to C# Dictionary
这篇关于将复杂的Map数据结构转换为F#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文