Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ocaml beginner here, didn't know you could restrict an Ocaml type to a string of a given length !! How would you go about that ?? Cheers :)


The easiest way is probably to define a private subtype of string (type small_string = private string) with smart constructors that enforces the restriction at runtime. This often means that creating such values may fail, but if you have a value of this type you are assured that the constraint on the size holds.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: