What does an apostrophe in front of a list ( '[Something] ) mean in Haskell?

前端 未结 2 1863
醉酒成梦
醉酒成梦 2020-12-06 17:15

I was reading the Servant documentation and came across this line:

type UserAPI = \"users\" :> QueryParam \"sortby\" SortBy :> Get \'[JSON] [User]
         


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-06 18:04

    Quotes are used to distinguish type-level constructors vs. term-level constructors of promoted types.

    For instance:

    {-# LANGUAGE DataKinds #-}
    
    data Which = One | Two
    
    myPick :: Which -- Type
    myPick = One
    
    type MyPick :: Which -- Kind
    type MyPick = 'One
    

    By the way, the kind annotation type MyPick :: Which is not valid Haskell but it gives you an idea of the correspondence between the term and the type level. The closest you can get to this requires turning on another extension:

    {-# LANGUAGE TypeFamilies #-}
    
    type family MyPick :: Which where
      MyPick = 'One
    

提交回复
热议问题