feat: impl Hash for Array

This commit is contained in:
Shunsuke Shibayama 2023-09-18 19:44:37 +09:00
parent 53a43962e8
commit 57d3a23aed
7 changed files with 71 additions and 19 deletions

View file

@ -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):