Your problem stems from an incorrect schema. files
can currently only contain one GistContent
, which is unnecessarily limiting. Instead, you'd want to have a list of GistContent
s:
data Gist = Gist
{ description :: Text
, public :: Bool
, files :: [GistContent]
} deriving (Show, Generic)
Now consider another constraint on Gist
: each GistContent
must have a different filename
. A data structure that would enforce this would be Data.HashMap.Strict.HashMap
. Taking the filename
out of GistContent
and using the filename as a key:
data GistContent = GistContent
{ content :: Text
} deriving (Show, Generic)
data Gist = Gist
{ description :: Text
, public :: Bool
, files :: HashMap Text GistContent
} deriving (Show, Generic)
Everything works out.