Version française
Home     About     Download     Resources     Contact us    
Browse thread
Boxing wrt. unary constructors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: Boxing wrt. unary constructors
> This is probably a FAQ, but if I have a type
>   type abc = ABC of int
> then does Ocaml 2.00 use a boxed or unboxed repr. of values of this
> type?

Boxed.  While it would not be hard to make a special case for
one-constructor datatypes, this is not currently done in the OCaml
compiler.  However, you can use type abstraction to obtain much of the
same effects while keeping an unboxed representation:

        (struct type abc = int  let abc x = x  let proj_abs x = x end :
         sig    type abc     val abc: int->abc   val proj_abc: abc->int end)

Regards,

- Xavier Leroy