Why not place exn in function signature?

Note that this is not strictly true in the general sense; you can still achieve safety with sum types (variants) to represent your errors, as many have expressed in this thread. You can always replace your raise Cant_alloc expressions into Error Cant_alloc (which in turn requires you to return Ok size instead of just size) and treat it as a result type instead of checked exceptions. You would then be “forced” to handle that error on sayhi function.