From 96bd2316525bb8790d4f047834c0ca6750155583 Mon Sep 17 00:00:00 2001 From: Ilya Portnov Date: Sun, 2 Oct 2011 19:12:42 +0600 Subject: [PATCH] Simplify some instances. --- JVM/Builder/Monad.hs | 2 +- JVM/ClassFile.hs | 9 +++++---- JVM/Converter.hs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/JVM/Builder/Monad.hs b/JVM/Builder/Monad.hs index 85aaa5e..01e93f1 100644 --- a/JVM/Builder/Monad.hs +++ b/JVM/Builder/Monad.hs @@ -72,7 +72,7 @@ lookupPool :: Constant Direct -> Pool Direct -> Maybe Word16 lookupPool c pool = fromIntegral `fmap` findIndex (== c) (M.elems pool) -addNT :: Binary (Signature a) => NameType a -> Generate Word16 +addNT :: HasSignature a => NameType a -> Generate Word16 addNT (NameType name sig) = do let bsig = encode sig x <- addItem (CNameType name bsig) diff --git a/JVM/ClassFile.hs b/JVM/ClassFile.hs index 0359320..2b7e1e7 100644 --- a/JVM/ClassFile.hs +++ b/JVM/ClassFile.hs @@ -128,7 +128,8 @@ data AccessFlag = deriving (Eq, Show, Ord, Enum) -- | Fields and methods have signatures. -class HasSignature a where +class (Binary (Signature a), Show (Signature a), Eq (Signature a)) + => HasSignature a where type Signature a instance HasSignature Field where @@ -142,12 +143,12 @@ data NameType a = NameType { ntName :: B.ByteString, ntSignature :: Signature a } -instance Show (Signature a) => Show (NameType a) where +instance (HasSignature a) => Show (NameType a) where show (NameType n t) = toString n ++ ": " ++ show t -deriving instance Eq (Signature a) => Eq (NameType a) +deriving instance HasSignature a => Eq (NameType a) -instance (Binary (Signature a)) => Binary (NameType a) where +instance HasSignature a => Binary (NameType a) where put (NameType n t) = putLazyByteString n >> put t get = NameType <$> get <*> get diff --git a/JVM/Converter.hs b/JVM/Converter.hs index 777bac6..5993d54 100644 --- a/JVM/Converter.hs +++ b/JVM/Converter.hs @@ -175,7 +175,7 @@ constantPoolArray ps = pool n = fromIntegral $ M.size ps - convertNameType :: (HasSignature a, Binary (Signature a)) => Word16 -> NameType a + convertNameType :: (HasSignature a) => Word16 -> NameType a convertNameType i = let (CNameType n s) = pool ! i in NameType n (decode s) -- 2.25.1