История изменений
Исправление korvin_, (текущая версия) :
В TypeScript и Typed/Racket такое присваивание корректно.
#lang typed/racket
(define-type T1 (U Integer Float))
(define-type T2 (U Float Integer))
(: x T1)
(define x 100)
(: xx T2)
(define xx x)
(displayln "OK")
В Ocaml такое будет работать для полиморфных вариантов:
type t1 =
[
| `I of int
| `F of float
]
type t2 =
[
| `F of float
| `I of int
]
let () =
let x : t1 = `I 100 in
let xx : t2 = x in
ignore xx ; (* avoid unused-var compile error *)
print_endline "OK"
тэги всё равно нужны, присвоить x : t1 = 100 не удастся.
Исходная версия korvin_, :
В TypeScript и Typed/Racket такое присваивание корректно.
#lang typed/racket
(define-type T1 (U Integer Float))
(define-type T2 (U Float Integer))
(: x T1)
(define x 100)
(: xx T2)
(define xx x)
(displayln "OK")
В Ocaml такое будет работать для полиморфных вариантов:
type t1 =
[
| `I of int
| `F of float
]
type t2 =
[
| `F of float
| `I of int
]
let () =
let x : t1 = `I 100 in
let xx : t2 = x in
ignore xx ; (* avoid unused-var compile error *)
print_endline "OK"
тэги всё равно нужны, присвоить x : t1 = 100 не удастся.