Shouldn't we be allowed to assign anything to `unknown`?

i keep having to use Obj.magi to assign to unknown, shouldn’t it be possible to just assign anything to unknown, but not assign unknown to anything (without Obj.magic, I guess)?

What’s your use case for unknown here? We’ve discussed this with the team but the opinion is that you should not go from something to unknown, unknown should be used for bindings and external data and should then be parsed, you should not go the other way.

I have have a BSON parser that can fail when an attempt is made to parse a leaf into an expected structure. let’s say the BSON parse expects an int at a leaf, but it sees something else (e.g., a string):

exception InvalidValue(unknown)

this is a case where i want to be able to just throw(InvalidValue(whateverValueThereWas)) without having to sprinkle Obj.magic. that lets the caller inspect the value, but we don’t know (or care) what it is when we throw beyond that it wasn’t what we wanted. unknown is enough for the caller to be able to carefully inspect/log whatever it was

why don’t you use the type of the unparsed BSON for the payload of this exception?

this is absolutely a fair point that i should consider, although i also have this:

  let anyOrThrow = obj =>
    switch any(obj) {
    | Some(o) => o
    | None => throw(InvalidValue(Obj.magic(obj)))
    }

as part of the parser, where obj is a'

well this definitely calls for an Obj.magic anyway ^^