git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add contexts to instance declarations
f761337Phil Freeman
src/Language/PureScript/Declarations.hs+1−1
@@ -44,5 +44,5 @@ data Declaration
44 | FixityDeclaration Fixity String
44 | FixityDeclaration Fixity String
45 | ImportDeclaration ModuleName (Maybe [Either Ident ProperName])
45 | ImportDeclaration ModuleName (Maybe [Either Ident ProperName])
46 | TypeClassDeclaration ProperName String [Declaration]
46 | TypeClassDeclaration ProperName String [Declaration]
47− | TypeInstanceDeclaration (Qualified ProperName) Type [Declaration]
47+ | TypeInstanceDeclaration [(Qualified ProperName, Type)] (Qualified ProperName) Type [Declaration]
48 deriving (Show, D.Data, D.Typeable)
48 deriving (Show, D.Data, D.Typeable)
src/Language/PureScript/Parser/Common.hs+1−1
@@ -81,7 +81,7 @@ builtInOperators = [ "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "
81 , "==", "!=", "&&", "||", "&", "^", "|", "!!", "!" ]
81 , "==", "!=", "&&", "||", "&", "^", "|", "!!", "!" ]
82
82
83reservedOpNames :: [String]
83reservedOpNames :: [String]
84−reservedOpNames = builtInOperators ++ [ "->", "=", ".", "\\" ]
84+reservedOpNames = builtInOperators ++ [ "=>", "->", "=", ".", "\\" ]
85
85
86identStart :: P.Parsec String u Char
86identStart :: P.Parsec String u Char
87identStart = P.lower <|> P.oneOf "_"
87identStart = P.lower <|> P.oneOf "_"
src/Language/PureScript/Parser/Declarations.hs+7−1
@@ -18,6 +18,7 @@ module Language.PureScript.Parser.Declarations (
18 parseModules
18 parseModules
19) where
19) where
20
20
21+import Data.Maybe (fromMaybe)
21import Control.Applicative
22import Control.Applicative
22import qualified Text.Parsec as P
23import qualified Text.Parsec as P
23
24
@@ -108,11 +109,16 @@ parseTypeClassDeclaration = do
108parseTypeInstanceDeclaration :: P.Parsec String ParseState Declaration
109parseTypeInstanceDeclaration :: P.Parsec String ParseState Declaration
109parseTypeInstanceDeclaration = do
110parseTypeInstanceDeclaration = do
110 reserved "instance"
111 reserved "instance"
112+ deps <- do
113+ deps <- P.optionMaybe (parens (commaSep1 ((,) <$> parseQualified properName <*> parseType)))
114+ indented
115+ reservedOp "=>"
116+ return deps
111 className <- indented *> parseQualified properName
117 className <- indented *> parseQualified properName
112 ty <- indented *> parseType
118 ty <- indented *> parseType
113 indented *> reserved "where"
119 indented *> reserved "where"
114 members <- mark (P.many (same *> parseValueDeclaration))
120 members <- mark (P.many (same *> parseValueDeclaration))
115− return $ TypeInstanceDeclaration className ty members
121+ return $ TypeInstanceDeclaration (fromMaybe [] deps) className ty members
116
122
117parseDeclaration :: P.Parsec String ParseState Declaration
123parseDeclaration :: P.Parsec String ParseState Declaration
118parseDeclaration = P.choice
124parseDeclaration = P.choice
src/Language/PureScript/Sugar/TypeClasses.hs+1−1
@@ -29,7 +29,7 @@ desugarModule (Module name decls) = Module name $ concatMap desugarDecl decls
29
29
30desugarDecl :: Declaration -> [Declaration]
30desugarDecl :: Declaration -> [Declaration]
31desugarDecl (TypeClassDeclaration name arg members) = typeClassDictionaryDeclaration name arg members : map (typeClassMemberToDictionaryAccessor name arg) members
31desugarDecl (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) = []
33desugarDecl other = [other]
33desugarDecl other = [other]
34
34
35typeClassDictionaryDeclaration :: ProperName -> String -> [Declaration] -> Declaration
35typeClassDictionaryDeclaration :: ProperName -> String -> [Declaration] -> Declaration
src/Language/PureScript/TypeChecker.hs+1−1
@@ -187,7 +187,7 @@ typeCheckAll currentModule (ImportDeclaration moduleName idents : rest) = do
187 constructs fn _ = error $ "Invalid arguments to constructs: " ++ show fn
187 constructs fn _ = error $ "Invalid arguments to constructs: " ++ show fn
188typeCheckAll moduleName (TypeClassDeclaration name arg decls : rest) = do
188typeCheckAll moduleName (TypeClassDeclaration name arg decls : rest) = do
189 typeCheckAll moduleName rest
189 typeCheckAll moduleName rest
190−typeCheckAll moduleName (TypeInstanceDeclaration name ty decls : rest) = do
190+typeCheckAll moduleName (TypeInstanceDeclaration deps name ty decls : rest) = do
191 typeCheckAll moduleName rest
191 typeCheckAll moduleName rest
192
192
193qualifyAllUnqualifiedNames :: (Data d) => ModuleName -> Environment -> d -> d
193qualifyAllUnqualifiedNames :: (Data d) => ModuleName -> Environment -> d -> d