uhhh
uhhh

Reputation: 7

Lists with various data types inside ocaml

I'm new to ocaml so I am wondering why this doesn't work.

let lst : (string * int * char) list = ["1"; 2; '3'];;

And how would I be able to fix it?

Upvotes: 0

Views: 259

Answers (1)

Shawn
Shawn

Reputation: 165

This is a list of tuples that are shaped like (string * int * char).

Most likely what you're looking for is a variant type. https://dev.realworldocaml.org/variants.html

type mix = | Str of string | Int of int | Char of char

let lst : mix list = [Str "1"; Int 2; Char '3']

Upvotes: 3

Related Questions