|
|
|
|
|
by lmm
2963 days ago
|
|
> In crystal, the compiler always knows the concrete values of the type parameters of any generic before typing it. Hmm. Does that mean you can't have a generic method in a separate compilation unit from where it gets used? > I really am interested in knowing more about what you said about union types being non compositional because I'm definitely not a type theorist. I'm not really a type theorist, I'm just thinking about e.g. if you have a method like: def doSomething[A](userSuppliedValue: A) = {
val x = if(someCondition) Some(userSuppliedValue) else None
x match {
case Some(a) => y ...
case None => z ...
}
x match {
case None => v ...
case Some(a) => w ...
}
}
then the compiler knows that if we take branch y we will also take branch w and if we take branch z we will also take branch v. Whereas if you do the same thing with an inclusive union type, that's true most of the time but not when userSuppliedValue is null. |
|
I'm confused by your example too. If you mean replacing matching None with testing for nil, then you'd have to replace Some(T) with an `else`, then the compiler absolutely can prove that if you take one branch you take the other - given that x is not assigned to (not sure why the compiler would want to prove that though). And after all that I'm not sure how your example relates to, or what you even mean by "noncompositional".