@@ -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 = ""
85−-- becomes
85+-- becomes:
87+-- <TypeClassDeclaration Foo ...>
87-- type Foo a = { foo :: a -> a }
89-- type Foo a = { foo :: a -> a }
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
93-- fooString :: {} -> Foo String
97-- fooString :: {} -> Foo String
94−-- fooString _ = { foo: \s -> s ++ s }
98+-- fooString _ = <TypeClassDictionaryConstructorApp Foo { foo: \s -> s ++ s }>
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 }>
99-- {- Superclasses -}
103-- {- Superclasses -}
101−-- ...
105+-- <TypeClassDeclaration Sub ...>
107+-- type Sub a = { sub :: a
108+-- , "__superclass_Foo_0" :: {} -> Foo a
111+-- -- As with `foo` above, this type is unchecked at the declaration
112+-- sub :: forall a. (Sub a) => a
113+-- sub dict = dict.sub
115+-- subString :: {} -> Sub String
116+-- subString _ = { sub: "",
117+-- , "__superclass_Foo_0": \_ -> <SuperClassDictionary Foo String>
120+-- and finally as the generated javascript:
122+-- function Foo(foo) {
126+-- var foo = function (dict) {
130+-- var fooString = function (_) {
131+-- return new Foo(function (s) {
136+-- var fooArray = function (__dict_Foo_15) {
137+-- return new Foo(map(foo(__dict_Foo_15)));
140+-- function Sub(__superclass_Foo_0, sub) {
141+-- this["__superclass_Foo_0"] = __superclass_Foo_0;
145+-- var sub = function (dict) {
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\>
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