I am new to Haskell. I am trying to create a simple JSON API client, and have found one implemented for Twitter in Haskell. My current goal is outlined in this question, but the same thing is demonstrated below.
In that Twitter/Haskell API code, there is this snippet:
https://github.com/himura/twitter-types/blob/master/Web/Twitter/Types.hs#L577-L587
type EntityIndices = [Int]
data Entity a = Entity {
entityBody :: a, -- ^ The detail information of the specific entity types (HashTag, URL, User)
entityIndices :: EntityIndices, -- ^ The character positions the Entity was extracted from
} deriving (Show, Eq)
instance FromJSON a => FromJSON (Entity a) where
parseJSON v@(Object o) = Entity <$> parseJSON v
<*> o .: "indices"
parseJSON _ = mzero
What is happening here?
First, from my understanding, That data
block is a Generalized Algebraic Data Type, because you are passing a parameter into the type data Entity a
, and that a
is being used in entityBody :: a
.
Second, how do you instantiate that Entity
generalized algebraic data type?
Finally, what is happening here?
instance FromJSON a => FromJSON (Entity a) where
What does that =>
mean?
I can break this into multiple questions if that helps, but it all seems sorta interconnected.