Dominic Steinitz
Sat, 02 Oct 2004 04:07:39 -0700
GHC accepts this with -fglasgow-exts
instance (Ord a, Bits a, Bounded a, Integral a, LargeWord a,
Bits b, Bounded b, Integral b, LargeWord b) =>
Bounded (LargeKey a b) where
minBound = 0
maxBound =
fromIntegral $
(1 + fromIntegral (maxBound::b))*
(1 + fromIntegral (maxBound::a)) - 1Hugs rejects it with +N -98 with
Since I've already declared b to be Bounded, it looks like a bug in Hugs.
Dominic.
=======================================================================
module Codec.Encryption.LargeKey (Word128,Word192,Word256,LargeWord) where
import Data.Word import Data.Bits import Numeric import Char
-- Keys have certain capabilities.
class LargeWord a where largeWordToInteger :: a -> Integer integerToLargeWord :: Integer -> a largeWordPlus :: a -> a -> a largeWordAnd :: a -> a -> a largeWordOr :: a -> a -> a largeWordShift :: a -> Int -> a largeWordXor :: a -> a -> a largeBitSize :: a -> Int
-- Word64 is a key in the obvious way.
instance LargeWord Word64 where largeWordToInteger = toInteger integerToLargeWord = fromInteger largeWordPlus = (+) largeWordAnd = (.&.) largeWordOr = (.|.) largeWordShift = shift largeWordXor = xor largeBitSize = bitSize
-- Define larger keys from smaller ones.
data LargeKey a b = LargeKey a b deriving (Eq, Ord)
instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) =>
Num (LargeKey a b) where
(+) = largeWordPlus
fromInteger = integerToLargeWord-- Larger keys are instances of Bits provided their constituents are keys.
instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) =>
Bits (LargeKey a b) where
(.&.) = largeWordAnd
(.|.) = largeWordOr
xor = largeWordXor
shift = largeWordShift
bitSize = largeBitSizeinstance (Ord a, Bits a, Bounded a, Integral a, LargeWord a,
Bits b, Bounded b, Integral b, LargeWord b) =>
Bounded (LargeKey a b) where
minBound = 0
maxBound =
fromIntegral $
(1 + fromIntegral (maxBound::b))*
(1 + fromIntegral (maxBound::a)) - 1instance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) =>
Integral (LargeKey a b) where
toInteger = largeWordToIntegerinstance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) => Real (LargeKey a b)
instance Enum (LargeKey a b)
type Word96 = LargeKey Word32 Word64 type Word128 = LargeKey Word64 Word64 type Word160 = LargeKey Word32 Word128 type Word192 = LargeKey Word64 Word128 type Word224 = LargeKey Word32 Word192 type Word256 = LargeKey Word64 Word192 _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell