constructor - OCaml - creating custom types of custom types -
if have data types identification , person, how use them?
type identification = name of string | ss of int * int;; type person = personal_info of identification;;
how make person type has identification? how construct variable these types in it..?
something this:
person1 = personal_info (name = "cody") (ss = (231,4534));; val person1 : person = .....
your identification
type specifies either name or social security number. looks me want have both of them. should use record type:
type ident = { name: string; ss: int * int }
since person
type has 1 variant, redundant (not couldn't useful in cases).
here value of type ident
:
{ name = "cody"; ss = (231, 4534) }
if want use person
type, this:
type person = pi of ident
a value of type this:
pi { name = "cody"; ss = (231, 4534) }
Comments
Post a Comment