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

A typical way to handle this in a functional language would be to create a datatype with a name like "PositiveInt", which just contains an Int inside it. However, in a language like OCaml, you can make it so that users of this type cannot directly create it, and instead must use a function like "makePosInt", which would check that its argument is positive, then give you back a value of type PositiveInt containing your data.

I'm not too experienced with this though, so this is pretty much the extent of my knowledge on this topic.



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

Search: