Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use private types in the interface #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

yallop
Copy link

@yallop yallop commented May 22, 2017

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
Copy link

cfcs commented Sep 12, 2017

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.

None yet

2 participants