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

Type variable is interpreted as () when requesting properties (and maybe other things) #7

Closed
JeffreyBenjaminBrown opened this issue Aug 2, 2019 · 2 comments

Comments

@JeffreyBenjaminBrown
Copy link

In an earlier issue, you wrote:

in your last example ("I see the property, but no value:"),
that was probably because you used () as property value type.
If the property value is (), greskell won't try parsing the
value at all and just return (). Use Int instead in this case.

However, I had not actually specified the type (). Rather, I had omitted the type signature. Experimenting after your comment, I found that if I use a type variable, it's as if I specified ():

findPeopleProperties :: [Key AVertex d]
  -> GTraversal Transform () (AVertexProperty d)

Is this behavior intentional? It seems as if () serves as the default type when none is specified -- but even when the type is unspecified (as in the variable d above), the AVertexProperty object indicates the payload's type, as in the flagged line below:

AVertexProperty
  { avpId = GValue
    { unGValue = GraphSON
      { gsonType = Just "g:Int64"              # flag
      , gsonValue = GNumber -2.042816214e9 } }
  , avpLabel = "suchness"
  , avpValue = ()
  , avpProperties = PropertyMapSingle
    ( PropertyMapGeneric ( fromList [] ) ) }

Therefore a more closely-fitting default type might be possible.

@debug-ito
Copy link
Owner

Is this behavior intentional? It seems as if () serves as the default type when none is specified

No, that is not intentional, and GHC usually doesn't do such kind of type defaulting. The reason why the type variable was defaulting to () is probably because you used GHCi. For convenience, GHCi enables ExtendedDefaultRules extension by default, which allows type defaulting to ().

I tried your example in IndexTest.hs in my test branch. When I ran stack build, GHC failed because it could not infer the result type.

I think the current behavior is not a problem, because (1) as I said, GHC (not GHCi) is conservative in type defaulting, so it can detect ambiguous type variables (2) in practice, you will use the result data obtained from the server. In that case, you will assume a concrete type for it anyway.

Therefore a more closely-fitting default type might be possible.

It might be. However, types are usually compile-time information in Haskell, while GraphSON's @type field is run-time information. It's impossible to set compile-time information from run-time information. Maybe it's possible to use a type dependent on some run-time information in Haskell, but I don't know how to do it. If we could customize the default types used by GHCi, it would be convenient in the interactive environment.

GraphSON's @type field is mainly for dynamic type languages such as Groovy and Python, I guess. In Haskell, we can use it for validation purposes. To do that, you can use parseTypedGraphSON function from Data.Greskell.GraphSON in your implementation of FromGraphSON class.

@JeffreyBenjaminBrown
Copy link
Author

Ah, that makes sense. Thanks!

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

2 participants