gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:38:44 25 4
gpt4 key购买 nike

我很好奇如何将它从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com