haskell-graphql / graphql-api

Write type-safe GraphQL services in Haskell
BSD 3-Clause "New" or "Revised" License
406 stars 35 forks source link

Refactor Value kind definition #207

Closed zhujinxuan closed 5 years ago

zhujinxuan commented 5 years ago

Currently, our AST.Value is defined as

data Value = ValueVariable Variable
           | ValueInt Int32
....
           | ValueObject ObjectValue
           | ValueNull
           deriving (Eq, Show)

However, it becomes difficult for https://github.com/haskell-graphql/graphql-api/issues/206, because we cannot define a symbol that

_value :: Value -> Int
_value :: Value -> ObjectValue -- conflicting type

Perhaps it is better to define Value as

data Value a = Value {
   __value :: a
  , position :: PositionInfo
} | ValueNull {position :: PositionInfo}

Then we can type the _value as

_value :: Value a ->a

and it can also reduce a lot of boilerplate pattern in value related functions.