mirror of
https://github.com/erg-lang/erg.git
synced 2025-12-23 05:36:48 +00:00
50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
f(x: Nat): Int = x
|
|
y: Ratio = f 1
|
|
# Erg's type checking does not necessarily enlarge the type. So this is OK.
|
|
z: Int = y
|
|
# But this is invalid.
|
|
invalid: 10..<20 = z #ERR
|
|
|
|
for! [(1, 2)], ((i, j),) =>
|
|
k = i + 1 # OK
|
|
print! k
|
|
for! [(1, 2)], ((i, j),) =>
|
|
k = i + "a" # ERR
|
|
print! k
|
|
for! zip([1], ["a"]), ((i: Int, s: Str),) =>
|
|
k = i + 1
|
|
l = s + "b"
|
|
print! k, l
|
|
# ERR: i should be Int
|
|
for! zip([1], ["a"]), ((i: Str, s: Str),) => # ERR
|
|
k = i + "a"
|
|
print! k
|
|
for! zip([1], ["a"]), ((i, s),) =>
|
|
k = i + "a" # ERR
|
|
print! k
|
|
|
|
for! zip([1+1], ["a"+"b"]), ((i, s),) => # i: Nat, s: Str
|
|
print! i + 1
|
|
print! s + "b"
|
|
print! s + 1 # ERR
|
|
print! i + "a" # ERR
|
|
|
|
for! "aaa", a =>
|
|
print! a # OK
|
|
for! "aaa", a =>
|
|
print! a + 1 # ERR
|
|
|
|
inty|T :> Nat, T <: Int|(x: T) = x + x
|
|
inty 0 # OK
|
|
inty 1.1 # ERR
|
|
|
|
_: List!({"a", "b"}, 2) = !["a", "b"] # OK
|
|
_: List!({"a", "b", "c"}, 2) = !["a", "b"] # OK
|
|
_: List!({"a", "c"}, 2) = !["a", "b"] # ERR
|
|
_: List!({"a"}, 2) = !["a", "b"] # ERR
|
|
|
|
ii _: Iterable(Iterable(Str)) = None
|
|
ii [1] # ERR
|
|
ii [[1]] # ERR
|
|
ii [["a"]]
|
|
ii ["aaa"] # Str <: Iterable Str
|