mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
feat: impl Hash for Array
This commit is contained in:
parent
53a43962e8
commit
57d3a23aed
7 changed files with 71 additions and 19 deletions
|
@ -3,13 +3,16 @@ from _erg_int import Int
|
|||
from _erg_int import IntMut # don't unify with the above line
|
||||
from _erg_control import then__
|
||||
|
||||
|
||||
class Nat(Int):
|
||||
def __init__(self, i):
|
||||
if int(i) < 0:
|
||||
raise ValueError("Nat can't be negative: {}".format(i))
|
||||
|
||||
def try_new(i): # -> Result[Nat]
|
||||
if i >= 0:
|
||||
return Nat(i)
|
||||
else:
|
||||
return Error("Nat can't be negative")
|
||||
return Error("Nat can't be negative: {}".format(i))
|
||||
|
||||
def times(self, f):
|
||||
for _ in range(self):
|
||||
|
@ -38,6 +41,8 @@ class NatMut(IntMut): # and Nat
|
|||
value: Nat
|
||||
|
||||
def __init__(self, n: Nat):
|
||||
if int(n) < 0:
|
||||
raise ValueError("Nat can't be negative: {}".format(n))
|
||||
self.value = n
|
||||
|
||||
def __int__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue