@@ -96,6 +96,24 @@ parseImportDeclaration = do
9696 idents <- P.optionMaybe $ parens $ commaSep1 (Left <$> parseIdent <|> Right <$> properName)
9797 return $ ImportDeclaration moduleName idents
9898
99+parseTypeClassDeclaration :: P.Parsec String ParseState Declaration
100+parseTypeClassDeclaration = do
101+ reserved "class"
102+ className <- indented *> properName
103+ ident <- indented *> parseIdent
104+ indented *> reserved "where"
105+ members <- mark (P.many (same *> parseTypeDeclaration))
106+ return $ TypeClassDeclaration className ident members
107+
108+parseTypeInstanceDeclaration :: P.Parsec String ParseState Declaration
109+parseTypeInstanceDeclaration = do
110+ reserved "instance"
111+ className <- indented *> properName
112+ ty <- indented *> parseType
113+ indented *> reserved "where"
114+ members <- mark (P.many (same *> parseValueDeclaration))
115+ return $ TypeInstanceDeclaration className ty members
116+
99117parseDeclaration :: P.Parsec String ParseState Declaration
100118parseDeclaration = P.choice
101119 [ parseDataDeclaration
@@ -104,7 +122,9 @@ parseDeclaration = P.choice
104122 , parseValueDeclaration
105123 , parseExternDeclaration
106124 , parseFixityDeclaration
107− , parseImportDeclaration ] P.<?> "declaration"
125+ , parseImportDeclaration
126+ , parseTypeClassDeclaration
127+ , parseTypeInstanceDeclaration ] P.<?> "declaration"
108128
109129parseModule :: P.Parsec String ParseState Module
110130parseModule = do