Elm 中的通用类型字典
Generic typed dictionary in Elm
我很好奇如何将其从 F# 移植到 Elm:
type World =
{ Rooms: Map<RoomId, Room>
Player: Player }
RoomId, Room之间的东西叫做泛型字典。
看这里上下文:https://github.com/ShalokShalom/Elchemist/blob/master/Game.fs
我读了一些关于类型变量的内容,它们有帮助吗?
如果可以,怎么做?
谢谢 :D
Elm 的语法类似。
Edit - @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:
type World =
{ Rooms: Map<RoomId, Room>
Player: Player }
RoomId, Room之间的东西叫做泛型字典。 看这里上下文:https://github.com/ShalokShalom/Elchemist/blob/master/Game.fs
我读了一些关于类型变量的内容,它们有帮助吗? 如果可以,怎么做?
谢谢 :D
Elm 的语法类似。
Edit - @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
}