Reputation: 167
This is how I'm currently defining bytes and bits for a program in ocaml
:
type bit = Zero of int | One of int
type byte_t = bit * bit * bit * bit * bit * bit * bit * bit
type block = byte_t * byte_t * byte_t * byte_t * byte_t * byte_t
These are super lengthy definitions, and will cause a lot of problems while implementation.
Is there a better way to implement these?
Upvotes: 0
Views: 503
Reputation: 9030
In the real world OCaml programming, we normally use char
for the data type for bytes. It has 8bits.
Your definition of bit
is strange. It should be simply:
type bit = Zero | One
or you can use bool
instead.
If you are working on homework or something to learn algebraic way of data construction, the story may be different.
Upvotes: 2