git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update typeclass desugaring comment
commit596eb0b415eed92f45a232de552ae0ea3e56741c authorGary Burgess <gary.burgess@gmail.com> dateFri 18 Jul 2014, 22:36 (12 years ago) parent06bd87e
1 file changed+56−14
src/Language/PureScript/Sugar/TypeClasses.hs+56−14
src/Language/PureScript/Sugar/TypeClasses.hs+56−14
@@ -82,31 +82,73 @@ desugarModule _ = error "Exports should have been elaborated in name desugaring"
8282-- instance subString :: Sub String where
8383-- sub = ""
8484--
85−-- becomes
85+-- becomes:
86+--
87+-- <TypeClassDeclaration Foo ...>
8688--
8789-- type Foo a = { foo :: a -> a }
8890--
89−-- foreign import foo "function foo(dict) {\
90−-- \ return dict.foo;\
91−-- \}" :: forall a. (Foo a) => a -> a
91+-- -- this following type is marked as not needing to be checked so a new Abs
92+-- -- is not introduced around the definition in type checking, but when
93+-- -- called the dictionary value is still passed in for the `dict` argument
94+-- foo :: forall a. (Foo a) => a -> a
95+-- foo dict = dict.foo
9296--
9397-- fooString :: {} -> Foo String
94−-- fooString _ = { foo: \s -> s ++ s }
98+-- fooString _ = <TypeClassDictionaryConstructorApp Foo { foo: \s -> s ++ s }>
9599--
96100-- fooArray :: forall a. (Foo a) => Foo [a]
97−-- fooArray = { foo: map foo }
101+-- fooArray = <TypeClassDictionaryConstructorApp Foo { foo: map foo }>
98102--
99103-- {- Superclasses -}
100104--
101−-- ...
105+-- <TypeClassDeclaration Sub ...>
106+--
107+-- type Sub a = { sub :: a
108+-- , "__superclass_Foo_0" :: {} -> Foo a
109+-- }
110+--
111+-- -- As with `foo` above, this type is unchecked at the declaration
112+-- sub :: forall a. (Sub a) => a
113+-- sub dict = dict.sub
114+--
115+-- subString :: {} -> Sub String
116+-- subString _ = { sub: "",
117+-- , "__superclass_Foo_0": \_ -> <SuperClassDictionary Foo String>
118+-- }
119+--
120+-- and finally as the generated javascript:
121+--
122+-- function Foo(foo) {
123+-- this.foo = foo;
124+-- };
125+--
126+-- var foo = function (dict) {
127+-- return dict.foo;
128+-- };
129+--
130+-- var fooString = function (_) {
131+-- return new Foo(function (s) {
132+-- return s + s;
133+-- });
134+-- };
135+--
136+-- var fooArray = function (__dict_Foo_15) {
137+-- return new Foo(map(foo(__dict_Foo_15)));
138+-- };
139+--
140+-- function Sub(__superclass_Foo_0, sub) {
141+-- this["__superclass_Foo_0"] = __superclass_Foo_0;
142+-- this.sub = sub;
143+-- };
144+--
145+-- var sub = function (dict) {
146+-- return dict.sub;
147+-- };
102148--
103−-- subString :: {} -> { __superclasses :: { "Foo": {} -> Foo String }, sub :: String }
104−-- subString _ = {
105−-- __superclasses: {
106−-- "Foo": \_ -> <dictionary placeholder to be inserted during type checking\>
107−-- }
108−-- sub: ""
109−-- }
149+-- var subString = function (_) {
150+-- return new Sub(fooString, "");
151+-- };
110152-}
111153desugarDecl :: ModuleName -> Declaration -> Desugar (Maybe DeclarationRef, [Declaration])
112154desugarDecl mn d@(TypeClassDeclaration name args implies members) = do