On 12/26/10 09:30, Ivo Seeba wrote:
> I need a list, or other structures, that enables insert elements of
> different types.
> I need a list like [("A",3);("B",[2;3;4]);("A",[[3;4];[1;2]])];.
> or like
> let st = ref ();;
> let insert b = (st:=(b,!st));;
> insert ("A",3);;
> insert ("B",[1;2]);;
> 
> or.
> 
> let st = ();;
> let insert b = ( let st = (b,st) );;
> ..
> Can anybody help me?

Variants (aka sum types, algebraic data types or tagged unions) are made
for that purpose:

type value = Int of int | List of value list

let l = [
  ("A", Int 3);
  ("B", List [ Int 2; Int 3; Int 4] );
  ("A", List [ List [ Int 3; Int 4 ];
               List [ Int 1; Int 2 ] ])
]


Martin


> --
> All the best and a happy new year: Ivo
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "ocaml-developer" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/ocaml-developer?hl=en
> For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html

-- 
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html

Reply via email to