deriving
can be use for a limited, fixed list of typeclass. The problem here is that you need to tell the compiler that the function you have defined are an instance of class AST
for the datatype Token
, like so:
class AST a where
children :: a -> [a]
prefix :: a -> String
suffix :: a -> String
node :: a -> [String]
instance AST Token where
children v = []
prefix v = ""
suffix v = ""
node v = [prefix v] ++ (concatMap node $ children v) ++ [suffix v]
data Token = Line { lnName :: String, lnLines :: Int }
| LineList { llLines :: [Token] }
| Init String
| Main String
| Step { stId :: String, stDuration :: Float }
| Scene { scId :: String, scTokens :: [Token] }
| Sequence { sqId :: String , sqScenes :: [Token] }
| File {flContents :: [Token]}
deriving (Show)