Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic typed dictionary in Elm

Tags:

f#

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

like image 370
Matthias Schuster Avatar asked Apr 07 '18 21:04

Matthias Schuster


1 Answers

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
    }
like image 196
Chad Gilbert Avatar answered Sep 19 '22 10:09

Chad Gilbert