How to add instance declaration for Typeable

[...] wants to find all the places in the outdated code base, that the variable foo is used in the conditional case if.

---- Why is Haskell worth learning

The code I have is

import Language.C import Data.Generics import Control.Monad import Text.Read parseAndFindFoos :: FilePath -> IO (Either ParseError [Position]) parseAndFindFoos path = liftM (fmap findFooLocations) (parseCFilePre path) findFooLocations input = fmap posOf (listify isIfOfInterest input) isIfOfInterest (CIf cond _ _ _) = not (null (listify isFooIdent cond)) isFooIdent (Ident name) = (name == "foo") 

How can I add an instance declaration for (Typeable Lexeme)?

+4
source share
1 answer
 {-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-} import Data.Typeable deriving instance Typeable Lexeme 

must work.

However, there is one mistake, and this is really true if this instance must be defined in the library. Lexeme will create an instance of Typeable , and if any other library includes a similar instance, there will be a conflict. Unfortunately, all you can really do to not add a global instance of Typeable Lexeme is either to hope that it will be added to the base at some point, or to use the newtype wrapper and manually wrap and deploy Lexeme .

 newtype LexemeWrapper = WrapLexeme { unwrapLexeme :: Lexeme } deriving Typeable 
+8
source

All Articles