Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

What is the ' doing to that list?

like image 800
Marcelo Lazaroni Avatar asked Jul 01 '17 20:07

Marcelo Lazaroni


People also ask

What does apostrophe do in Haskell?

It is indeed convention to use a "tick" at the end of a function name to denote a slightly modified version of a previously defined function, but this is nothing other than convention - the apostrophe character has no intrinsic meaning in the Haskell language.

What does single quote mean in Haskell?

Single quotes means single character, double quotes means character array (string). In Haskell, 'c' is a single character ( Char ), and "c" is a list of characters ( [Char] ).


1 Answers

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
like image 177
gallais Avatar answered Oct 19 '22 02:10

gallais