@@ -53,9 +53,24 @@ declToJs opts mp (BindingGroupDeclaration vals) e =
5353 [ JSVariableIntroduction ident (Just (valueToJs opts mp e val)),
5454 setProperty (identToJs ident) (JSVar ident) mp ]
5555 ) vals
56−declToJs _ mp (ExternMemberDeclaration member ident _) _ =
57− Just [ JSFunction (Just ident) [Ident "value"] (JSBlock [JSReturn (JSAccessor member (JSVar (Ident "value")))]),
58− setProperty (show ident) (JSVar ident) mp ]
56+declToJs _ mp (ExternMemberDeclaration member ident ty) _
57+ | returnsFunction ty =
58+ Just [ JSFunction (Just ident) [Ident "value"] (JSBlock
59+ [ JSReturn $ JSApp (JSAccessor "bind" (JSAccessor member (JSVar (Ident "value")))) [JSVar (Ident "value")]
60+ ]),
61+ setProperty (show ident) (JSVar ident) mp ]
62+ | otherwise =
63+ Just [ JSFunction (Just ident) [Ident "value"] (JSBlock
64+ [ JSReturn $ JSAccessor member (JSVar (Ident "value"))
65+ ]),
66+ setProperty (show ident) (JSVar ident) mp ]
67+ where
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'
73+ isFunction _ = False
5974declToJs _ mp (DataDeclaration _ _ ctors) _ =
6075 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), maybeTy) ->
6176 let