// implement a type that can be unvalid or valid. // It's a replacement of Optional, but can be allocated on stack, so no heap allocaton needed. // When unvalid, it should be not possible to get unvalid value, thats why abstract type is used. // bool b: true means valid, false unvalid abst@ype valid(a:t@ype,b:bool) = (a,bool b) typedef Valid(a:t@ype) = [b : bool] valid(a,b) // Wraps valid value. fn {a:t@ype} create_valid(value : a) : valid(a,true) // Creates unvalid type. fn {a:t@ype} create_unvalid() : valid(a,false) // Only function that allows getting value. Only accepts valid values. fn {a:t@ype} unwrap_valid(valid(a,true)) : a