Matthias Schuster
Matthias Schuster

Reputation: 147

Generic typed dictionary in Elm

I am curious how to port this from F# to Elm:

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

The thing between RoomId, Room is called a generic type dictionary. See here the context: https://github.com/ShalokShalom/Elchemist/blob/master/Game.fs

I read something about type variables, can they help? If so, how?

Thanks :D

Upvotes: 6

Views: 213

Answers (1)

Chad Gilbert
Chad Gilbert

Reputation: 36375

Elm's syntax would be similar.

Edit - @dogbert is right about RoomId not being comparable in my original answer. You could use a type alias of a String instead.

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
    }

Upvotes: 7

Related Questions