Looking at the Haskell Servant package, there is an initial example of defining a webservice API as:
-- GET /date
type MyAPI = "date" :> Get '[JSON] Date
-- GET /time/:tz
:<|> "time" :> Capture "tz" Timezone :> Get '[JSON] Time
I'm having trouble understanding what this means and would appreciate an explanation for the following:
:>
and :<|>
are infix constructors. Does this type declaration mean that they are defined here or they are used here? Or maybe :>
is defined here but :<|>
is defined elsewhere? Or something else? Not sure how to read this type.
What is '[JSON]
? Is this some sort of type-level literal list? What does the quote do?
The (infix) constructors are used here, and they must be defined elsewhere in data
or newtype
declarations. type
declarations do not produce constructors of any sort ever.
'[JSON]
is indeed a type level list, equivalent to JSON ': '[]
. The single quote indicates that a data constructor is being lifted to a type constructor. I'm not sure what deep significance that has, but at least it avoids confusion that might otherwise arise from the fact that data constructors and type constructors can share names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With