2 ms·
Rather than "parsing", is it a form of type casting? To me it feels like downcasting in OOP from a parent class (more general) to a child class (more specific)
by ohwellhere 4y ago
Rather than "parsing", is it a form of type casting?
To me it feels like downcasting in OOP from a parent class (more general) to a child class (more specific).
In Swift there is the "conditional downcast" operator `as?` which does what the article discusses with the potentially failing conversion to `Maybe thing`: it returns the new more constrained as `.Some(thing)`, or returns `.None` if it is not the appropriate type.
You can also go between non-hierarchical types with casting in most languages, like from ints to floats to strings, etc.
Following from all of that and your language suggestion, I might call the practice a "constraining type cast".
---
Although, all of that written, and I expect it's conversion rather than casting.