Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Object access using variable

$
0
0

May be possible while keeping soundness by using Polymorphic Variants as long as it matches ones of the object keys

type flower = {
  color:  string,
  petals: int
}

let flower = {
  color: "red",
  petals: 5
}

type flowerKeys = [ #color | #petals ]

let key: flowerKeys = #color

flower[key]

Viewing all articles
Browse latest Browse all 2592

Trending Articles