@@ -53,9 +53,24 @@ declToJs opts mp (BindingGroupDeclaration vals) e =
53 [ JSVariableIntroduction ident (Just (valueToJs opts mp e val)),
53 [ JSVariableIntroduction ident (Just (valueToJs opts mp e val)),
54 setProperty (identToJs ident) (JSVar ident) mp ]
54 setProperty (identToJs ident) (JSVar ident) mp ]
56−declToJs _ mp (ExternMemberDeclaration member ident _) _ =
56+declToJs _ mp (ExternMemberDeclaration member ident ty) _
57+ | returnsFunction ty =
57− Just [ JSFunction (Just ident) [Ident "value"] (JSBlock [JSReturn (JSAccessor member (JSVar (Ident "value")))]),
58+ Just [ JSFunction (Just ident) [Ident "value"] (JSBlock
59+ [ JSReturn $ JSApp (JSAccessor "bind" (JSAccessor member (JSVar (Ident "value")))) [JSVar (Ident "value")]
61+ setProperty (show ident) (JSVar ident) mp ]
63+ Just [ JSFunction (Just ident) [Ident "value"] (JSBlock
64+ [ JSReturn $ JSAccessor member (JSVar (Ident "value"))
58− setProperty (show ident) (JSVar ident) mp ]
66+ setProperty (show ident) (JSVar ident) mp ]
68+ returnsFunction (Function _ ret) = isFunction ret
69+ returnsFunction (ForAll _ ty') = returnsFunction ty'
70+ returnsFunction _ = error "Expected function type in declToJs"
71+ isFunction (Function _ _) = True
72+ isFunction (ForAll _ ty') = isFunction ty'
59declToJs _ mp (DataDeclaration _ _ ctors) _ =
74declToJs _ mp (DataDeclaration _ _ ctors) _ =
60 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), maybeTy) ->
75 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), maybeTy) ->