project-m36 icon indicating copy to clipboard operation
project-m36 copied to clipboard

allow `Tupleable` instances to include default relvar name

Open agentm opened this issue 7 years ago • 8 comments

Currently, the Tupleable interface does not include any specific binding to any relvar. @3noch suggested that the Tupleable typeclass could carry a default relvar name likely for use in define/assign/insert/update/delete operations. Tupleable values would still be able to be extracted from arbitrary queries.

agentm avatar Oct 13 '17 00:10 agentm

You could encode this as a separate type class.

3noch avatar Oct 13 '17 00:10 3noch

I guess the following would work nicely

class HasRelVarName a where
  relVarName :: RelVarName

and then we could add a default that names it using Generics?

ruhatch avatar Dec 12 '17 16:12 ruhatch

This is exactly what I had in mind (and implemented in one of my projects). It works great.

3noch avatar Dec 12 '17 16:12 3noch

Awesome ;) did you implement a default for it?

ruhatch avatar Dec 12 '17 16:12 ruhatch

No I didn't get that far. But I'm on the fence about it anyway. I like things like that to be explicit, but certainly for toy projects it's nicer.

3noch avatar Dec 12 '17 16:12 3noch

I guess it would still be reasonably explicit because you would have to write

instance HasRelVarName a where

anyway. But I guess you're right that you might as well add the string at that point. Although as mentioned in the Beam tutorial, in GHC 8.2 that can be changed to a deriving (HasRelVarName) on the type which would be nice.

ruhatch avatar Dec 12 '17 17:12 ruhatch

@3noch In your definition of the class do you get an ambiguous type error? I get one on relVarName because it ignores the a.

ruhatch avatar Dec 12 '17 17:12 ruhatch

I am thinking tentatively that there should be indeed two classes: Tupleable and something else for the relvar name. The reason is that, if Tupleable has a single hard-coded relvar name, then one would need a second Tupleable instance to marshal the Haskell values to/form a different relvar. That seems rather limiting, especially considering that Tupleable instances don't need to use all the attributes of the target relation.

Alternatively, we could stick the relvar name into the Tupleable instance while making two expression-generating APIs, one using the instance's relvar name and one using any name (like we have now). That sounds like it could clutter what should be an easy-to-use API, though.

What do you think?

agentm avatar Dec 12 '17 22:12 agentm