mth/yeti — pull request #8 by chrisichris (2013-09-18 21:27:11+00:00)
Title: VariantCasePatter for 'Some' tags which also applies if the runtime-value ...

...is a plain value and not a yeti.lang.Tag

Some-Variant case patterns also match a runtime-value which is not a yeti.lang.Tag ie

case (1 as ~Object) unsafely_as Some number of
Some x : x == 1;
None () : false;
esac;

evaluates to true, before a ClassCastException was thrown because the case-value is not yeti.lang.Tag

My use-case is easier runtime converstion of Json objects to yeti-structs.

In Json has no Some/None values instead optional fields are either expressed as plain values (Some) or null.

So converting the the json-object:
{ 'optional' : 2} to a yeti (runtime) struct is currently ambitios it can be either a) {optional = 2} or b) {optional = Some 2}.

Without further type-information a generic function (jsonToStruct is string -> 'a) function has to decide to use a) or b) ie {optional = 2}. However in this case the value can currentl not be treated optional.

>json = jsonToStruct '{"optional" : 2}';
{optional = 2}
>json.optional
2
>case json.optional of Some x: x; None (): 0 esac
//throws ClassCastExcpetion number is no yeti.lang.Tag

With the codechange proposed with this pull-request the last expression would evaluate
>case json.optional of Some x: x; None (): 0 esac
2 is number