git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update typeclass desugaring comment
596eb0bGary Burgess
src/Language/PureScript/Sugar/TypeClasses.hs+56−14
@@ -82,31 +82,73 @@ desugarModule _ = error "Exports should have been elaborated in name desugaring"
82-- instance subString :: Sub String where
82-- instance subString :: Sub String where
83-- sub = ""
83-- sub = ""
84--
84--
85−-- becomes
85+-- becomes:
86+--
87+-- <TypeClassDeclaration Foo ...>
86--
88--
87-- type Foo a = { foo :: a -> a }
89-- type Foo a = { foo :: a -> a }
88--
90--
89−-- foreign import foo "function foo(dict) {\
91+-- -- this following type is marked as not needing to be checked so a new Abs
90−-- \ return dict.foo;\
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
91−-- \}" :: forall a. (Foo a) => a -> a
94+-- foo :: forall a. (Foo a) => a -> a
95+-- foo dict = dict.foo
92--
96--
93-- fooString :: {} -> Foo String
97-- fooString :: {} -> Foo String
94−-- fooString _ = { foo: \s -> s ++ s }
98+-- fooString _ = <TypeClassDictionaryConstructorApp Foo { foo: \s -> s ++ s }>
95--
99--
96-- fooArray :: forall a. (Foo a) => Foo [a]
100-- fooArray :: forall a. (Foo a) => Foo [a]
97−-- fooArray = { foo: map foo }
101+-- fooArray = <TypeClassDictionaryConstructorApp Foo { foo: map foo }>
98--
102--
99-- {- Superclasses -}
103-- {- Superclasses -}
100--
104--
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+-- };
102--
148--
103−-- subString :: {} -> { __superclasses :: { "Foo": {} -> Foo String }, sub :: String }
104−-- subString _ = {
149+-- var subString = function (_) {
105−-- __superclasses: {
150+-- return new Sub(fooString, "");
106−-- "Foo": \_ -> <dictionary placeholder to be inserted during type checking\>
107−-- }
108−-- sub: ""
109−-- }
151+-- };
110-}
152-}
111desugarDecl :: ModuleName -> Declaration -> Desugar (Maybe DeclarationRef, [Declaration])
153desugarDecl :: ModuleName -> Declaration -> Desugar (Maybe DeclarationRef, [Declaration])
112desugarDecl mn d@(TypeClassDeclaration name args implies members) = do
154desugarDecl mn d@(TypeClassDeclaration name args implies members) = do