Skip to content

Use private types in the interface#2

Open
yallop wants to merge 3 commits into
hannesm:masterfrom
yallop:private-types
Open

Use private types in the interface#2
yallop wants to merge 3 commits into
hannesm:masterfrom
yallop:private-types

Conversation

@yallop

@yallop yallop commented May 22, 2017

Copy link
Copy Markdown

At present, Uint8.t and Uint16.t are both exposed as equal to int. Consequently, it's easy to build invalid values of those types:

# Usane.Uint8.((257 : t));;
- : Usane.Uint8.t = 257

This PR marks the types Uint8.t and Uint16.t private in the interface so only the functions in the interface, which maintain validity, can be used to create values of those types. It's still easy and free to convert from a Uint8.t or a Uint16.t to an int by coercing:

# let x = Usane.Uint8.of_int 16 ;;
val x : Usane.Uint8.t = 16
# (x :> int);;
- : int = 16

@cfcs

cfcs commented Sep 12, 2017

Copy link
Copy Markdown

I think this is a great addition!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants