f# - Elm 中的通用类型字典

标签 f# elm

我很好奇如何将它从 F# 移植到 Elm:

type World =
    { Rooms: Map<RoomId, Room> 
      Player: Player }

RoomId、Room 之间的东西叫做泛型类型字典。
请参阅此处的上下文:https://github.com/ShalokShalom/Elchemist/blob/master/Game.fs

我读了一些关于类型变量的内容,他们能帮上忙吗?
如果是这样,如何?

感谢:D

最佳答案

Elm 的语法是类似的。

编辑 - @dogbert 关于 RoomId 在我原来的答案中没有可比性是正确的。您可以改用 String 的类型别名。

type alias RoomId = String

type alias Room =
    { id: RoomId
    , details: Details
    , items: List Item
    , exits: Exits 
    }

type alias World =
    { rooms: Dict RoomId Room
    , player: Player
    }

关于f# - Elm 中的通用类型字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49712062/

相关文章:

elm - 如何处理输入字段中的 Enter 键按下?

compiler-errors - Elm找不到Elm空白错误

json - Elm:使用 elm-decode-pipeline 解码嵌套的对象数组

f# - 我可以在 F# PCL 库中使用 System.Timers.Timer 吗?

f# - 使用异步工作流进行并行化的最佳实践

f# - 使用 FParsec 解析变量声明

f# - 如何避免重复声明相似类型?

javascript - 如何在Elm中实现Vue的transition group功能?

f# - 是否可以使用 webpart GET 值创建类实例

compiler-errors - 榆树错误 : I am looking for one of the following things: "' "