How to handle "Unknown" or "Any" type in ReasonML?


#1

Hey there!

Does ReasonML have some sort of ANY type that can be used for helper functions if you don’t know about certain types beforehand?

E.g. I have a function that helps with http requests, that would need a type something like this:

type fetchState =
  | Loading
  | Error(fetchErr)
  | Loaded(array(ANYTHING));

Depending on the JsonDecoders I pass to the function, the return type for Loaded(array(...)) can be anything. Does anyone know how to do this with the above snippet?


#2

Hi, @feluxe!

You’ll want to use a parameterized type for that. Here are some docs:

And here’s a clip from a book:
http://reasonmlhub.com/exploring-reasonml/ch_variants.html#parameterized-variants


#3

@splodingsocks This was exactly what I was looking for :smiley: Thanks so much!