← Back to index

How to convert a polymorphic variable to a string?

Thu May 06 2021

ReScript version: rescript@9.1.2

We can use the coercion operator :>.

type color = [#red | #green | #blue]

// Coerce the polyvar to a string
let toString = (color: color): string => (color :> string)

let red: string = toString(#red)