moduleData.SizedInt(SizedInt)whereimportData.BitsimportTypesnewtype(NaturalTnT)=>SizedIntnT=SizedIntIntegersizeT::SizedIntnT->nTsizeT_=undefinedmask::forallnT.NaturalTnT=>nT->Integermask_=bit(fromIntegerT(undefined::nT))-1signBit::forallnT.NaturalTnT=>nT->IntsignBit_=fromIntegerT(undefined::nT)-1isNegative::forallnT.NaturalTnT=>SizedIntnT->BoolisNegative(SizedIntx)=testBitx$signBit(undefined::nT)instanceNaturalTnT=>Eq(SizedIntnT)where(SizedIntx)==(SizedInty)=x==y(SizedIntx)/=(SizedInty)=x/=yinstanceNaturalTnT=>Show(SizedIntnT)whereshowsPrecprecn=showsPrecprec$toIntegerninstanceNaturalTnT=>Read(SizedIntnT)wherereadsPrecprecstr=[(fromIntegern,str)|(n,str)<-readsPrecprecstr]instanceNaturalTnT=>Ord(SizedIntnT)wherea`compare`b=toIntegera`compare`toIntegerbinstanceNaturalTnT=>Bounded(SizedIntnT)whereminBound=SizedInt$negate$1`shiftL`(fromIntegerT(undefined::nT)-1)maxBound=SizedInt$(1`shiftL`(fromIntegerT(undefined::nT)-1))-1instanceNaturalTnT=>Enum(SizedIntnT)wheresuccx|x==maxBound=error$"Enum.succ{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to take `succ' of maxBound"|otherwise=x+1predx|x==minBound=error$"Enum.succ{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to take `pred' of minBound"|otherwise=x-1fromEnum(SizedIntx)|x>toInteger(maxBound::Int)=error$"Enum.fromEnum{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to take `fromEnum' on SizedInt greater than maxBound :: Int"|x<toInteger(minBound::Int)=error$"Enum.fromEnum{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to take `fromEnum' on SizedInt smaller than minBound :: Int"|otherwise=fromIntegerxtoEnumx|x'>toInteger(maxBound::SizedIntnT)=error$"Enum.fromEnum{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to take `fromEnum' on SizedInt greater than maxBound :: SizedInt "++show(fromIntegerT(undefined::nT))|x'<toInteger(minBound::SizedIntnT)=error$"Enum.fromEnum{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to take `fromEnum' on SizedInt smaller than minBound :: SizedInt "++show(fromIntegerT(undefined::nT))|otherwise=fromIntegerx'wherex'=toIntegerxinstanceNaturalTnT=>Num(SizedIntnT)where(SizedInta)+(SizedIntb)=fromInteger$a+b(SizedInta)*(SizedIntb)=fromInteger$a*bnegate(SizedIntn)=fromInteger$(n`xor`mask(undefined::nT))+1a-b=a+(negateb)fromIntegern|n>0=SizedInt$n.&.mask(undefined::nT)fromIntegern|n<0=negate$fromInteger$negatenfromInteger_=SizedInt0abss|isNegatives=negates|otherwise=ssignums|isNegatives=-1|s==0=0|otherwise=1instanceNaturalTnT=>Real(SizedIntnT)wheretoRationaln=toRational$toIntegerninstanceNaturalTnT=>Integral(SizedIntnT)wherea`quot`b=fromInteger$toIntegera`quot`toIntegerba`rem`b=fromInteger$toIntegera`rem`toIntegerba`div`b=fromInteger$toIntegera`div`toIntegerba`mod`b=fromInteger$toIntegera`mod`toIntegerba`quotRem`b=let(quot,rem)=toIntegera`quotRem`toIntegerbin(fromIntegerquot,fromIntegerrem)a`divMod`b=let(div,mod)=toIntegera`divMod`toIntegerbin(fromIntegerdiv,fromIntegermod)toIntegers@(SizedIntx)=ifisNegativesthenletSizedIntx'=negatesinnegatex'elsexinstanceNaturalTnT=>Bits(SizedIntnT)where(SizedInta).&.(SizedIntb)=SizedInt$a.&.b(SizedInta).|.(SizedIntb)=SizedInt$a.|.b(SizedInta)`xor`SizedIntb=SizedInt$a`xor`bcomplement(SizedIntx)=SizedInt$x`xor`mask(undefined::nT)(SizedIntx)`shiftL`b|b<0=error$"Bits.shiftL{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to shift by negative amount"|otherwise=SizedInt$mask(undefined::nT).&.(x`shiftL`b)s@(SizedIntx)`shiftR`b|b<0=error$"Bits.shiftR{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to shift by negative amount"|isNegatives=SizedInt$mask(undefined::nT).&.((x`shiftR`b).|.(mask(undefined::nT)`shiftL`(fromIntegerT(undefined::nT)-b)))|otherwise=SizedInt$(mask(undefined::nT)).&.(x`shiftR`b)(SizedInta)`rotateL`b|b<0=error$"Bits.rotateL{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to rotate by negative amount"|otherwise=SizedInt$mask(undefined::nT).&.((a`shiftL`b).|.(a`shiftR`(fromIntegerT(undefined::nT)-b)))(SizedInta)`rotateR`b|b<0=error$"Bits.rotateR{SizedInt "++show(fromIntegerT(undefined::nT))++"}: tried to rotate by negative amount"|otherwise=SizedInt$mask(undefined::nT).&.((a`shiftR`b).|.(a`shiftL`(fromIntegerT(undefined::nT)-b)))bitSize_=fromIntegerT(undefined::nT)isSigned_=True