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

Restricting maybewires when inserting and updating #57

Open
bergmark opened this issue Aug 9, 2014 · 7 comments
Open

Restricting maybewires when inserting and updating #57

bergmark opened this issue Aug 9, 2014 · 7 comments

Comments

@bergmark
Copy link

bergmark commented Aug 9, 2014

Using the To type family discussed in #11 I've specialized inserts and updates to be

myInsert
  :: ( Default TableMaybeWrapper wires maybewires
     , Default (PPOfContravariant Assocer) maybewires maybewires
     , maybewires ~ To Maybe wires -- Added
     )
  => Connection -> Table wires -> Expr maybewires -> IO ()

myUpdate
  :: ( Default TableExprRunner wires wires'
     , Default (PPOfContravariant Assocer) maybewires maybewires
     , Default TableMaybeWrapper wires maybewires
     , maybewires ~ To Maybe wires -- Added
     )
  => Connection -> Table wires -> ExprArr wires' maybewires -> ExprArr wires' (Wire Bool) -> IO Int64

This improves type inference and seems to always be what I want. Assuming To would make it into opaleye, is there any reason to not restrict these functions?

@bergmark
Copy link
Author

bergmark commented Aug 9, 2014

With this you don't need to add a type signature around MakeExpr calls.

@tomjaguarpaw
Copy link
Collaborator

Ah this would be very helpful! What are the consequences for the API consumer? Does it force them to enable any extensions?

@bergmark
Copy link
Author

bergmark commented Aug 9, 2014

Nope!

@tomjaguarpaw
Copy link
Collaborator

Sounds very cool. Is it possible to substitute To Maybe wires for maybewires in the function signature, or does the equivalence have to be put in the context like that?

@bergmark
Copy link
Author

bergmark commented Aug 9, 2014

I thought no, but it seems like it works. It's requires replacing maybewires with To Maybe wires everywhere, but I think it's a good change.

@bergmark
Copy link
Author

bergmark commented Aug 9, 2014

Oh scratch the last part, it's possible to change it on just the top level, just forgot to replace one of the maybewires when I tried it out.

@bergmark
Copy link
Author

You still need to type all Nothings inside your type, but you can add a type signature for the entire record for this so you don't need to type each field explicitly, i.e. both fields in User below would be ambiguous without the type signature for u:

insertUser = myInsert userTable $ makeMaybeExpr u
  where
    u :: To Maybe User
    u = User Nothing (Just 1)

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

No branches or pull requests

2 participants