moduleData.SizedWord(SizedWord)whereimportData.BitsimportTypesnewtype(NaturalTnT)=>SizedWordnT=SizedWordIntegersizeT::SizedWordnT->nTsizeT_=undefinedmask::forallnT.NaturalTnT=>nT->Integermask_=bit(fromIntegerT(undefined::nT))-1instanceNaturalTnT=>Eq(SizedWordnT)where(SizedWordx)==(SizedWordy)=x==y(SizedWordx)/=(SizedWordy)=x/=yinstanceNaturalTnT=>Show(SizedWordnT)whereshowsPrecprecn=showsPrecprec$toIntegerninstanceNaturalTnT=>Read(SizedWordnT)wherereadsPrecprecstr=[(fromIntegern,str)|(n,str)<-readsPrecprecstr]instanceNaturalTnT=>Ord(SizedWordnT)wherea`compare`b=toIntegera`compare`toIntegerbinstanceNaturalTnT=>Bounded(SizedWordnT)whereminBound=0maxBound=SizedWord$(1`shiftL`(fromIntegerT(undefined::nT)))-1instanceNaturalTnT=>Enum(SizedWordnT)wheresuccx|x==maxBound=error$"Enum.succ{SizedWord "++show(fromIntegerT(undefined::nT))++"}: tried to take `succ' of maxBound"|otherwise=x+1predx|x==minBound=error$"Enum.succ{SizedWord "++show(fromIntegerT(undefined::nT))++"}: tried to take `pred' of minBound"|otherwise=x-1fromEnum(SizedWordx)|x>toInteger(maxBound::Int)=error$"Enum.fromEnum{SizedWord "++show(fromIntegerT(undefined::nT))++"}: tried to take `fromEnum' on SizedWord greater than maxBound :: Int"|x<toInteger(minBound::Int)=error$"Enum.fromEnum{SizedWord "++show(fromIntegerT(undefined::nT))++"}: tried to take `fromEnum' on SizedWord smaller than minBound :: Int"|otherwise=fromIntegerxtoEnumx|x>fromIntegral(maxBound::SizedWordnT)=error$"Enum.fromEnum{SizedWord "++show(fromIntegerT(undefined::nT))++"}: tried to take `fromEnum' on SizedWord greater than maxBound :: SizedWord "++show(fromIntegerT(undefined::nT))|x<fromIntegral(minBound::SizedWordnT)=error$"Enum.fromEnum{SizedWord "++show(fromIntegerT(undefined::nT))++"}: tried to take `fromEnum' on SizedWord smaller than minBound :: SizedWord "++show(fromIntegerT(undefined::nT))|otherwise=fromInteger$toIntegerxinstanceNaturalTnT=>Num(SizedWordnT)where(SizedWorda)+(SizedWordb)=fromInteger$a+b(SizedWorda)*(SizedWordb)=fromInteger$a*bnegates@(SizedWordn)=fromInteger$(n`xor`mask(sizeTs))+1a-b=a+(negateb)fromIntegern|n>0=SizedWord$n.&.mask(undefined::nT)fromIntegern|n<0=negate$fromInteger$negatenfromInteger_=SizedWord0abss=ssignums|s==0=0|otherwise=1instanceNaturalTnT=>Real(SizedWordnT)wheretoRationaln=toRational$toIntegerninstanceNaturalTnT=>Integral(SizedWordnT)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@(SizedWordx)=xinstanceNaturalTnT=>Bits(SizedWordnT)where(SizedWorda).&.(SizedWordb)=SizedWord$a.&.b(SizedWorda).|.(SizedWordb)=SizedWord$a.|.b(SizedWorda)`xor`SizedWordb=SizedWord$a`xor`bcomplement(SizedWordx)=SizedWord$x`xor`mask(undefined::nT)s@(SizedWordx)`shiftL`b|b<0=error$"Bits.shiftL{SizedWord "++show(bitSizes)++"}: tried to shift by negative amount"|otherwise=SizedWord$mask(undefined::nT).&.(x`shiftL`b)s@(SizedWordx)`shiftR`b|b<0=error$"Bits.shiftR{SizedWord "++show(bitSizes)++"}: tried to shift by negative amount"|otherwise=SizedWord$(x`shiftR`b)s@(SizedWordx)`rotateL`b|b<0=error$"Bits.rotateL{SizedWord "++show(bitSizes)++"}: tried to rotate by negative amount"|otherwise=SizedWord$mask(undefined::nT).&.((x`shiftL`b).|.(x`shiftR`(bitSizes-b)))s@(SizedWordx)`rotateR`b|b<0=error$"Bits.rotateR{SizedWord "++show(bitSizes)++"}: tried to rotate by negative amount"|otherwise=SizedWord$mask(undefined::nT).&.((x`shiftR`b).|.(x`shiftL`(bitSizes-b)))bitSize_=fromIntegerT(undefined::nT)isSigned_=False