git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Generate Javascript for type class dictionary getters
commita7e6d2c637ec8f506a3e20f18aed8671fdb08aa2 authorPhil Freeman <paf31@cantab.net> dateSun 12 Jan 2014, 19:36 (13 years ago) parentf761337
1 file changed+5−1
src/Language/PureScript/Sugar/TypeClasses.hs+5−1
src/Language/PureScript/Sugar/TypeClasses.hs+5−1
@@ -20,6 +20,7 @@ import Language.PureScript.Declarations
2020import Language.PureScript.Names
2121import Language.PureScript.Types
2222import Language.PureScript.Values
23+import Language.PureScript.CodeGen.JS.AST
2324
2425desugarTypeClasses :: [Module] -> [Module]
2526desugarTypeClasses = map desugarModule
@@ -40,7 +41,10 @@ typeClassDictionaryDeclaration name arg members = TypeSynonymDeclaration name [a
4041 memberToNameAndType _ = error "Invalid declaration in type class definition"
4142
4243typeClassMemberToDictionaryAccessor :: ProperName -> String -> Declaration -> Declaration
43−typeClassMemberToDictionaryAccessor name arg (TypeDeclaration ident ty) = ExternDeclaration ident Nothing (ForAll arg (ConstrainedType [(Qualified Nothing name, TypeVar arg)] ty))
44+typeClassMemberToDictionaryAccessor name arg (TypeDeclaration ident ty) =
45+ ExternDeclaration ident
46+ (Just (JSFunction (Just (Ident arg)) [Ident "dict"] (JSReturn (JSAccessor arg (JSVar (Ident "dict"))))))
47+ (ForAll arg (ConstrainedType [(Qualified Nothing name, TypeVar arg)] ty))
4448typeClassMemberToDictionaryAccessor _ _ _ = error "Invalid declaration in type class definition"
4549
4650{-