Can I ask a question? (array-related)

Hi, I’m an absolute newbie to ReScript, and have been grappling with this problem for hours and finally posting this in the forum. Pardon me if this forum is not intended for question-and-answer type of postings.

I want to have an array that contains multiple types of data, like let arr = [1, (“hello”,1), “world”]. I thought I could achieve this by using variant, like

let SuperType = 
| FirstType(int)
| SecondType(string)

and use it directly in the array,

type something = {
 types: array(SuperType)
}

but this does not work! What is the correct ReScript way doing this?
Last but not least, I’d like to ask your opinions on what would be the wise way to tackle problems I encounter in the course of developing with ReScript. Should I peruse the ReScript docs over and over to do it somehow in my own way | post issues in Github | ask in stackoverflow?

Hi there!

Types are always lower-cased in ReScript, so your example should go like this:

type superType = FirstType(int) | SecondType(string)

type something = {
  types: array<superType>
}

let mySomething = {
  types: [FirstType(1), SecondType("2")]
}

Hope this helps.

For the future, it would be probably the best to ask such questions on StackOverflow (don’t forget to use the rescript tag). We’ll keep an eye on that and try to answer questions there if possible.

1 Like

God. Thanks! it worked like a magic.
I will ask via stackoverflow! Thanks for the help and suggestion :slight_smile:

1 Like