123456789101112131415161718192021222324252627282930313233343536373839typet=Zero|Oneletzero=Zeroletone=Oneletadd(x:t)(y:t)=match(x,y)with|(Zero,Zero)->Zero|(Zero,One)|(One,Zero)->One|(One,One)->Zeroletneg(x:t)=xletsubxy=addx(negy)letmul(x:t)(y:t)=match(x,y)with(Zero,_)|(_,Zero)->Zero|(One,One)->Oneletdiv(x:t)(y:t)=matchywithZero->Stdlib.failwith"Z2: division by zero"|_->xlethash(x:t)=matchxwithZero->0|One->1letppfmtr(x:t)=matchxwith|Zero->Format.pp_print_stringfmtr"zero"|One->Format.pp_print_stringfmtr"one"letequal(x:t)(y:t)=match(x,y)with(Zero,Zero)->true|(One,One)->true|_->falseletcompare(x:t)(y:t)=match(x,y)with|(Zero,Zero)|(One,One)->0|(Zero,One)->-1|(One,Zero)->1letof_int(i:int)=ifimod2=0thenZeroelseOne