Suppose we have a Result and an alias for it:
type StachuResult<'a> = Result<'a, StachuError>
type StachuResult2<'a> = | Ok of 'a | Error of StachuError
We need to ensure that the names sync up during equality
let randomStachuErr(): StachuResult<Int> =
PACKAGE.Darklang.Stdlib.Result.OK 1
let random(): Result<Int, StachuError> =
StachuResult.Ok 1
random() == randomStachuError() // true
let randomStachuErr2(): StachuResult2<Int> =
PACKAGE.Darklang.Stdlib.Result.OK 1 // type error - also runtime error when we typecheck the return type
let randomStachuErr'(): StachuResult2<Int> =
StachuResult2.Ok
randomStachuErr'() == random() // false (type error)
StachuResult2.Ok
is not a Result, but StachuResult.Ok
is.
Our EEnum
needs to reflect what is typed - i.e. we wrote StachuResult.OK
, not just Result.Ok
. But then we later need to do the alias resolution to know that StachuResult.Ok
is equal to Result.Ok
EErrors
safelyProgramType.EEnum
would need to store both the alias definition and the resolved alias type