git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add contexts to instance declarations
commitf7613374cbfe7151159d61cfc6be5770fa5ccb52 authorPhil Freeman <paf31@cantab.net> dateSun 12 Jan 2014, 19:33 (13 years ago) parente0d0502
5 files changed+11−5
src/Language/PureScript/Declarations.hs+1−1 src/Language/PureScript/Parser/Common.hs+1−1 src/Language/PureScript/Parser/Declarations.hs+7−1 src/Language/PureScript/Sugar/TypeClasses.hs+1−1 src/Language/PureScript/TypeChecker.hs+1−1
src/Language/PureScript/Declarations.hs+1−1
@@ -44,5 +44,5 @@ data Declaration
4444 | FixityDeclaration Fixity String
4545 | ImportDeclaration ModuleName (Maybe [Either Ident ProperName])
4646 | TypeClassDeclaration ProperName String [Declaration]
47− | TypeInstanceDeclaration (Qualified ProperName) Type [Declaration]
47+ | TypeInstanceDeclaration [(Qualified ProperName, Type)] (Qualified ProperName) Type [Declaration]
4848 deriving (Show, D.Data, D.Typeable)
src/Language/PureScript/Parser/Common.hs+1−1
@@ -81,7 +81,7 @@ builtInOperators = [ "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "
8181 , "==", "!=", "&&", "||", "&", "^", "|", "!!", "!" ]
8282
8383reservedOpNames :: [String]
84−reservedOpNames = builtInOperators ++ [ "->", "=", ".", "\\" ]
84+reservedOpNames = builtInOperators ++ [ "=>", "->", "=", ".", "\\" ]
8585
8686identStart :: P.Parsec String u Char
8787identStart = P.lower <|> P.oneOf "_"
src/Language/PureScript/Parser/Declarations.hs+7−1
@@ -18,6 +18,7 @@ module Language.PureScript.Parser.Declarations (
1818 parseModules
1919) where
2020
21+import Data.Maybe (fromMaybe)
2122import Control.Applicative
2223import qualified Text.Parsec as P
2324
@@ -108,11 +109,16 @@ parseTypeClassDeclaration = do
108109parseTypeInstanceDeclaration :: P.Parsec String ParseState Declaration
109110parseTypeInstanceDeclaration = do
110111 reserved "instance"
112+ deps <- do
113+ deps <- P.optionMaybe (parens (commaSep1 ((,) <$> parseQualified properName <*> parseType)))
114+ indented
115+ reservedOp "=>"
116+ return deps
111117 className <- indented *> parseQualified properName
112118 ty <- indented *> parseType
113119 indented *> reserved "where"
114120 members <- mark (P.many (same *> parseValueDeclaration))
115− return $ TypeInstanceDeclaration className ty members
121+ return $ TypeInstanceDeclaration (fromMaybe [] deps) className ty members
116122
117123parseDeclaration :: P.Parsec String ParseState Declaration
118124parseDeclaration = P.choice
src/Language/PureScript/Sugar/TypeClasses.hs+1−1
@@ -29,7 +29,7 @@ desugarModule (Module name decls) = Module name $ concatMap desugarDecl decls
2929
3030desugarDecl :: Declaration -> [Declaration]
3131desugarDecl (TypeClassDeclaration name arg members) = typeClassDictionaryDeclaration name arg members : map (typeClassMemberToDictionaryAccessor name arg) members
32−desugarDecl (TypeInstanceDeclaration name ty members) = []
32+desugarDecl (TypeInstanceDeclaration deps name ty members) = []
3333desugarDecl other = [other]
3434
3535typeClassDictionaryDeclaration :: ProperName -> String -> [Declaration] -> Declaration
src/Language/PureScript/TypeChecker.hs+1−1
@@ -187,7 +187,7 @@ typeCheckAll currentModule (ImportDeclaration moduleName idents : rest) = do
187187 constructs fn _ = error $ "Invalid arguments to constructs: " ++ show fn
188188typeCheckAll moduleName (TypeClassDeclaration name arg decls : rest) = do
189189 typeCheckAll moduleName rest
190−typeCheckAll moduleName (TypeInstanceDeclaration name ty decls : rest) = do
190+typeCheckAll moduleName (TypeInstanceDeclaration deps name ty decls : rest) = do
191191 typeCheckAll moduleName rest
192192
193193qualifyAllUnqualifiedNames :: (Data d) => ModuleName -> Environment -> d -> d