Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a bind record codgen #6

Open
paluh opened this issue Aug 11, 2022 · 0 comments
Open

Add a bind record codgen #6

paluh opened this issue Aug 11, 2022 · 0 comments

Comments

@paluh
Copy link
Member

paluh commented Aug 11, 2022

We can imagine an extension to the current mkFFI which actually produces an record of bound methods / properties as follows like:

_Person ::
  { firstName :: Person -> Effect String
  , lastName :: Person -> Effect String
  , setFirstName :: Person -> String -> Effect Unit
  , setLastName :: Person -> String -> Effect Unit
  }
_Person = mkNewtypedFFI (Proxy :: Proxy Person)


bindPerson p =
  { firstName: _Person.firstName p
  , lastName: _Person.lastName p
  , setFirstName: _Person.setFirstName p
  , setLastName: _Person.setLastName p
  }

So finally users could just do:

do
  let
    p' = bindPerson p
  p'.setFirstName "John"
  n <- p'.firstName

We should just generate this bindPerson function using heterogenous and warn that there is an extra allocation behind the scene.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant