Table of Contents

Haskell Reserved words - Haskell keywords

Return to Reserved keywords, Reserved words, Reserved identifier, Keywords, Haskell, Haskell DevOps - Haskell SRE - Haskell CI/CD, Cloud Native Haskell - Haskell Microservices - Serverless Haskell, Haskell Security - Haskell DevSecOps, Functional Haskell, Haskell Concurrency, Haskell Data Science - Haskell and Databases, Haskell Machine Learning, Haskell Bibliography, Haskell Courses, Haskell Glossary, Awesome Haskell, Haskell GitHub, Haskell Topics

Also called: Haskell Language Keywords, Haskell Reserved Keywords, Haskell Keywords, Haskell Reserved Identifiers, Haskell Reserved words

Like any programming language, the Haskell language designates certain words that the Haskell compiler recognizes as special words. For that reason, you're not allowed to use them for Haskell naming | naming your Haskell constructs. The list of Haskell reserved words (also called Haskell keywords) is surprisingly short:

This page lists all Haskell keywords, feel free to edit. Hoogle searches will return results from this page. Please respect the Anchor macros.

For additional information you might want to look at the Haskell 2010 report.

!

Whenever a data constructor is applied, each argument to the constructor is evaluated if and only if the corresponding type in the algebraic datatype declaration has a strictness flag, denoted by an exclamation point. For example:

<haskell>

data STList a 
        = STCons a !(STList a)  -- the second argument to STCons will be 
                                -- evaluated before STCons is applied
        ]] | [[ STNil
</haskell>

to illustrate the difference between strict versus lazy constructor application, consider the following:

<haskell>

stList = STCons 1 undefined
lzList = (:)    1 undefined
stHead (STCons h _) = h -- this evaluates to undefined when applied to stList
lzHead (h : _)      = h -- this evaluates to 1 when applied to lzList
</haskell>

! is also used in the "bang patterns" (GHC extension), to indicate strictness in patterns:

<haskell> f !x !y = x + y </haskell>

'

<nowiki>''</nowiki>

-

This operator token is magic/irregular in the sense that <haskell>(- 1)</haskell> is parsed as the negative integer -1, rather than as an operator Section of an infix operator | section, as it would be for any other operator: <haskell>(* 1) :: Num a ⇒ a → a</haskell> <haskell>(++ “foo”) :: String → String</haskell>

It is syntactic sugar for the <hask>negate</hask> function in Prelude. See unary operator. If you want the section, you can use the <hask>subtract</hask> function or <hask>(+(-1))</hask>.

--

Starts a single-line comment, unless immediately followed by an operator character other than <hask>-</hask>:

<haskell> main = print “hello world” – this is a comment –this is a comment as well —this too foobar –+ this_is_the_second_argument_of_the_dash_dash_plus_operator </haskell>

The multi-line variant for comments is <hask>{- comment -}</hask>.

-<

-<<

->

  • The function type constructor:

<haskell> length :: [a] → Int </haskell>

  • In lambda functions:

<haskell> \x → x + 1 </haskell>

  • To denote alternatives in case statements:

<haskell> case Just 3 of

   Nothing -> False
   Just x  -> True
</haskell>

or with LambdaCase: <haskell> (\ case 1 → 0

     ; _ -> 1 )
</haskell>

or with MultiWayIf: <haskell> if ]] | 1 == 0 -> 1 | 1 == 2 -> 2 | * -> * -> * </haskell> * [[Functional dependencies <haskell> – This examples assumes that each type 'c' can “contain” only one type – i.e. type 'c' uniquely determines type 'elt' class Contains c elt ]] | c -> elt where ... </haskell> * [[View patterns

::

Read as “has type”:

<haskell> length :: [a] → Int </haskell>

“Length has type list-of-'a' to Int”

Or “has kind” (GHC specific):

<haskell> Either :: * →

  • → *

</haskell>

;

  • Statement separator in an explicit block (see layout)

<-

?

<haskell> ghci> :t ?foo ++ “bar” ?foo ++ “bar” :: (?foo::[Char]) ⇒ [Char] </haskell>

#

*

  • Is an ordinary operator name on the value level
  • On the kind level: The kind of boxed types (GHC-specific)

<haskell> ghci> :kind Int Int :: * </haskell>

@

  • Patterns of the form <hask>var@pat</hask> are called as-patterns, and allow one to use <hask>var</hask> as a name for the value being matched by <hask>pat</hask>. For example:
       
        case e of { xs@(x:rest) -> if x==0 then rest else xs }

   -- is equivalent to:
    let { xs = e } in
      case xs of { (x:rest) -> if x==0 then rest else xs }
   

[]] | [[, ]] | [[]

{-, -}

Everything between “{-” followed by a space and “-}” is a block comment.

<haskell> {- hello world -} </haskell>

]] | [[

as

Renaming module imports. Like <hask>qualified</hask> and <hask>hiding</hask>, <hask>as</hask> is not a reserved word but may be used as function or variable name.

<haskell> import qualified Data.Map as M

main = print (M.empty :: M.Map Int ()) </haskell>

<span id="case">case</span>, <span id="of">of</span>

A case expression has the general form

<haskell>

case e of { p1 match1 ; ... ; pn matchn }
</haskell>

where each

match

i is of the general form

<haskell> ]] | g1 -> e1 ... | <haskell> pat | in the <code>where</code> clause associated with that alternative. If one of the guards evaluates to <code>True</code>, the corresponding right-hand side is evaluated in the same environment as the guard. If all the guards evaluate to <code>False</code>, matching continues with the next alternative. If no match succeeds, the result is _ | class-decls class declaration] introduces a new type class and the overloaded operations that must be supported by any type that is an instance of that class. <haskell> class Num a where (+) :: a -> a -> a negate :: a -> a </haskell> == data == The [http://haskell.org/onlinereport/decls.html#user-defined-datatypes data] declaration is how one introduces new algebraic data [[types into Haskell. For example: <haskell> data Set a = NilSet

          ]] | [[ ConsSet a (Set a)
</haskell>

Another example, to create a datatype to hold an Abstract_syntax_tree | abstract syntax tree for an expression, one could use: <haskell>

data Exp = Ebin   Operator Exp Exp 
         ]] | [[ Eunary Operator Exp 
         ]] | [[ Efun   FunctionIdentifier [Exp] 
         ]] | [[ Eid    SimpleIdentifier
</haskell>

where the types

Operator, FunctionIdentifier

and

SimpleIdentifier

are defined elsewhere.

See the page on types for more information, links and examples.

data family

Declares a datatype family (see type families). GHC language extension.

data instance

Declares a datatype family instance (see type families). GHC language extension.

default

Ambiguities in the class Num are most common, so Haskell provides a way to resolve them—with a default declaration:

<haskell> default (Int) </haskell>

Only one default declaration is permitted per module, and its effect is limited to that module. If no default declaration is given in a module then it assumed to be:

<haskell>

 default (Integer, Double)
</haskell>

deriving

data and newtype declarations contain an optional deriving form. If the form is included, then derived instance declarations are automatically generated for the datatype in each of the named classes.

Derived instances provide convenient commonly-used operations for user-defined datatypes. For example, derived instances for datatypes in the class Eq define the operations == and /=, freeing the programmer from the need to define them.

<haskell> data T = A

      ]] | [[ B
      ]] | [[ C
      deriving (Eq, Ord, Show)
</haskell>

In the case of newtypes, GHC extends this mechanism to Cunning Newtype Deriving.

deriving instance

Standalone deriving (GHC language extension).

<haskell> {-# LANGUAGE StandaloneDeriving #-} data A = A

deriving instance Show A </haskell>

do

Syntactic sugar for use with monadic expressions. For example:

<haskell>

do { x ; result <- y ; foo result }
</haskell>

is shorthand for:

<haskell>

x >> 
y >>= \result ->
foo result
</haskell>

forall

This is a GHC/Hugs extension, and as such is not portable Haskell 98/2010. It is only a reserved word within types.

Type variables in a Haskell type expression are all assumed to be universally quantified; there is no explicit syntax for universal quantification, in standard Haskell 98/2010. For example, the type expression <hask>a → a</hask> denotes the type <hask>forall a. a →a</hask>. For clarity, however, we often write quantification explicitly when discussing the types of Haskell programs. When we write an explicitly quantified type, the scope of the forall extends as far to the right as possible; for example, <haskell> forall a. a → a </haskell> means <haskell> forall a. (a → a) </haskell>

GHC introduces a <hask>forall</hask> keyword, allowing explicit quantification, for example, to encode existential types: <haskell> data Foo = forall a. MkFoo a (a → Bool)

        ]] | [[ Nil

MkFoo :: forall a. a → (a → Bool) → Foo Nil :: Foo

[MkFoo 3 even, MkFoo 'c' isUpper] :: [Foo] </haskell>

foreign

A keyword for the Foreign Function Interface (commonly called the FFI) that introduces either a <hask>foreign import</hask> declaration, which makes a function from a non-Haskell library available in a Haskell program, or a <hask>foreign export</hask> declaration, which allows a function from a Haskell module to be called in non-Haskell contexts.

hiding

When importing modules, without introducing a name into scope, entities can be excluded by using the form <haskell> hiding (import1 , … , importn ) </haskell> which specifies that all entities exported by the named module should be imported except for those named in the list.

For example: <haskell> import Prelude hiding (lookup,filter,foldr,foldl,null,map) </haskell>

<span id="if">if</span>, <span id="then">then</span>, <span id="else">else</span>

A conditional expression has the form:

<haskell>

if e1 then e2 else e3
</haskell>

and returns the value of e2 if the value of e1 is True, e3 if e1 is False, and _]] | as | as, hiding | hiding , qualified | qualified and the page Import

<span id="infix">infix</span>, <span id="infixl">infixl</span>, <span id="infixr">infixr</span>

A fixity declaration gives the fixity and binding precedence of one or more operators. The integer in a fixity declaration must be in the range 0 to 9. A fixity declaration may appear anywhere that a type signature appears and, like a type signature, declares a property of a particular operator.

There are three kinds of fixity, non-, left- and right-associativity (infix, infixl, and infixr, respectively), and ten precedence levels, 0 to 9 inclusive (level 0 binds least tightly, and level 9 binds most tightly).

<haskell>

 module Bar where
   infixr 7 `op`
   op = ...
</haskell>

instance

An instance declaration declares that a type is an instance of a class and includes the definitions of the overloaded operations - called class methods - instantiated on the named type.

<haskell>

 instance Num Int  where
   x + y       =  addInt x y
   negate x    =  negateInt x
</haskell>

<span id="let">let</span>, <span id="in">in</span>

Let expressions have the general form:

<haskell>let { d1 ; … ; dn } in e</haskell>

They introduce a nested, lexically-scoped, mutually-recursive list of declarations (let is often called let rec in other languages). The scope of the declarations is the expression e and the right hand side of the declarations.

Within <hask>do</hask>-blocks or list comprehensions <hask>let { d1 ; … ; dn }</hask> without <hask>in</hask> serves to introduce local bindings.

[https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#the-mdo-notation mdo]

The recursive <hask>do</hask> keyword enabled by -fglasgow-exts.

module

Taken from: A Gentle Introduction to Haskell, Version 98

Technically speaking, a module is really just one big declaration which begins with the keyword module; here's an example for a module whose name is Tree:

<haskell> module Tree ( Tree(Leaf,Branch), fringe ) where

data Tree a = Leaf a ]] | Tree a -> [a] fringe (Leaf x) = [x] fringe (Branch left right) = fringe left ++ fringe right </haskell> == newtype == The <code>newtype</code> declaration is how one introduces a renaming for an algebraic data [[type into Haskell. This is different from

type

below, as a

newtype

requires a new constructor as well. As an example, when writing a compiler one sometimes further qualifies

Identifier

s to assist in type safety checks:

newtype SimpleIdentifier = SimpleIdentifier Identifier
newtype FunctionIdentifier = FunctionIdentifier Identifier

Most often, one supplies smart constructors and smart destructors | destructors for these to ease working with them.

See the page on types for more information, links and examples.

For the differences between

newtype

and

data

, see Newtype.

proc

proc (arrow abstraction) is a kind of lambda, except that it constructs an arrow instead of a function.

Arrow notation

qualified

Used to import a module, but not introduce a name into scope. For example, Data.Map exports lookup, which would clash with the Prelude version of lookup, to fix this:

<haskell> import qualified Data.Map

f x = lookup x – use the Prelude version g x = Data.Map.lookup x – use the Data.Map version </haskell>

Of course, Data.Map is a bit of a mouthful, so qualified also allows the use of as.

<haskell> import qualified Data.Map as M

f x = lookup x – use Prelude version g x = M.lookup x – use Data.Map version </haskell>

rec

The rec keyword can be used when the

-XDoRec

flag is given; it allows recursive bindings in a do-block.

<haskell> {-# LANGUAGE DoRec #-} justOnes = do { rec { xs ← Just (1:xs) }

             ; return (map negate xs) }
</haskell>

type

The

type

declaration is how one introduces an alias for an algebraic data type into Haskell. As an example, when writing a compiler one often creates an alias for identifiers:

<haskell> type Identifier = String </haskell>

This allows you to use

Identifer

wherever you had used

String

and if something is of type

Identifier

it may be used wherever a

String

is expected.

See the page on types for more information, links and examples.

Some common

type

declarations in the Prelude include:

<haskell> type FilePath = String type String = [Char] type Rational = Ratio Integer type ReadS a = String → [(a,String)] type ShowS = String → String </haskell>

type family

Declares a type synonym family (see type families). GHC language extension.

type instance

Declares a type synonym family instance (see type families). GHC language extension.

where

Fair Use Sources

Reserved Keywords: (Also called: Language Keywords, Reserved Keyword, Reserved Word, Keywords, Reserved Identifier, Reserved Identifiers) Ada Keywords, ALGOL 68 Keywords, Angular Keywords, Android Keywords, Apple iOS Keywords, ARM Assembly Keywords, Assembly Keywords, AWK Keywords, Bash Keywords, BASIC Keywords, C Keywords (https://en.cppreference.com/w/c/keyword), C Sharp Keywords | Keywords, dot NET Keywords | NET Keywords, C plus plus Keywords | C++ Keywords (https://en.cppreference.com/w/cpp/keyword), Clojure Keywords, COBOL Keywords, Dart Keywords, Delphi Keywords, Django Keywords, Elixir Keywords, Erlang Keywords, F Sharp Keywords, Fortran Keywords, Flask Keywords, Golang Keywords, Groovy Keywords, Haskell Keywords, Jakarta EE Keywords, Java Keywords, JavaScript Keywords, JCL Keywords, Julia Keywords, Kotlin Keywords, Lisp Keywords (Common Lisp Keywords), Lua Keywords, MATHLAB Keywords, Objective-C Keywords, OCaml‎ Keywords, Pascal Keywords, Perl Keywords, PHP Keywords, PL/I Keywords, PowerShell Keywords, Python Keywords, Quarkus Keywords, R Language Keywords, React.js Keywords, Rexx Keywords, RPG Keywords, Ruby Keywords, Rust Keywords, Scala Keywords, Spring Keywords, SQL Keywords, Swift Keywords, Transact-SQL Keywords, TypeScript Keywords, Visual Basic Keywords, Vue.js Keywords, X86 Assembly Keywords, X86-64 Assembly Keywords. (navbar_reserved_keywords - see also navbar_cpp_keywords)

Haskell: Haskell Fundamentals, Haskell Inventor - Haskell Language Designer: Lennart Augustsson, Paul Hudak, John Hughes, Simon Peyton Jones, John Launchbury, Erik Meijer, Philip Wadler in 1990 (see Conference on Functional Programming Languages and Computer Architecture (FPCA 1987); Haskell keywords, Haskell data structures - Haskell algorithms, Haskell syntax, Haskell OOP, Haskell compiler (ghc - Glorious Glasgow Haskell Compilation System), Haskell installation (brew install ghc, choco install ghc) Haskell IDEs, Haskell development tools, Haskell DevOps - Haskell SRE - Haskell CI/CD, Cloud Native Haskell - Haskell Microservices - Serverless Haskell, Haskell Security - Haskell DevSecOps, Haskell and databases, Haskell data science - Haskell DataOps, Haskell machine learning - Haskell DL, Haskell deep learning, Functional Haskell, Haskell concurrency - Haskell parallel programming - Async Haskell, Haskell and scientific computing, Haskell history, Haskell bibliography, Haskell courses, Haskell Glossary - Glossaire de Haskell - French, Haskell topics, Haskell courses, Haskell Standard Library, Haskell libraries, Haskell frameworks, Haskell scientific computing, Haskell research, Haskell GitHub, Written in Haskell, Haskell popularity, Haskell Awesome list, Haskell topics, Haskell Versions (navbar_haskell - see also navbar_haskell_standard_library, navbar_haskell_libraries, navbar_haskell_reserved_words, navbar_haskell_functional, navbar_haskell_concurrency, navbar_functional)


Cloud Monk is Retired ( for now). Buddha with you. © 2025 and Beginningless Time - Present Moment - Three Times: The Buddhas or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.