Haskell/GHC 記号の意味を検索するためのリファレンス集

【追記】(2021/12/25)
===================

2021/12/25時点で、このページの内容は古くなっています。
新しい内容は以下でメンテナンスを継続していますので、そちらを参照して下さい。
[英語版はこちら](https://github.com/takenobu-hs/haskell-symbol-search-cheatsheet/blob/master/README.md#readme)、[日本語版はこちら](https://zenn.dev/takenobu_hs/articles/384ea7b5c09ee4)です。

はじめに
=======

このページは、Haskell/GHCにおける記号の検索を支援するためのリファレンス集です。
（オリジナルはGitHubの[こちら](https://github.com/takenobu-hs/haskell-symbol-search-cheatsheet/blob/master/README.md#readme)ですが、日本語でも検索しやすいようにQiitaにも載せておきます。）

Haskell/GHCの幾つかの機能は、記号（シンボル）で構成表現されているため、Google検索等のサーチエンジンによる検索が難しくなっています。
このページは、基本的な構文以外のいくつかの記号について、その代表的な呼称と、仕様書やユーザーガイド（英語版）へのリンクと、簡単なコード例を記載しています。

なお、記号で構成されている対象が関数名（例えば、 `.`, `$`, `<*>`, `>>=`, など）の場合については、以下の検索エンジンで検索できます。

  * [Hoogle search on Stackage](https://www.stackage.org)
  * [Hoogle on Haskell.org](https://www.haskell.org/hoogle) | [Hoogle 5 on Haskell.org](https://hoogle.haskell.org/)

それでは、Happy Haskelling!




---
`!` : "strictness flag" （正格性フラグ）
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-680004.2) \]

```Haskell
data Vec = Vec !Int
```


---
`!` : "bang pattern" （バンパターン）
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#bang-patterns-informal) \]

```Haskell
f1 !x = 
```


---
`#` : "MagicHash"
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#the-magic-hash) \]

```Haskell
data Int = I# Int#
```


---
`#` : "OverloadedLabels"
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#overloaded-labels) \]

```Haskell
example = #x (Point 1 2)
```


---
`#` : Cプリプロセッサのディレクティブ
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/phases.html#options-affecting-the-c-pre-processor) \]

```Haskell
#include "MachDeps.h"
```


---
`#` : hsc2hsコマンドのオペレータ
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/utils.html#input-syntax) \]

```Haskell
flag = #const VER_MAJORVERSION
```


---
`$( )` : Template Haskellのsplice構文
------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#template-haskell) \]

```Haskell
two = $(add1 1)
```


---
`$$( )` : Typed Template Haskellのsplice構文
------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#template-haskell) \]

```Haskell
two = $$(add1 1)
```


---
`'` : 識別子の構成文字としてのシングルクォート
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-180002.4) \]

```Haskell
xs' = f ys
```


---
`'` : 昇格されたコンストラクタ（promoted constructors）のプレフィクス
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#datatype-promotion) \]

```
type * = TYPE 'LiftedRep
```


---
`'` `''` : Template Haskellのquote構文
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/%7Eghc/latest/docs/html/users_guide/glasgow_exts.html#th-syntax) \]

```
makeLenses ''FooBar
```


---
`()` : "unit type" (ユニット型)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-650004.1.2) \] \[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1220006.1.5) \]

```Haskell
main :: IO ()
```


---
`()` : "unit expression" (値としてのユニット)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-380003.9) \] \[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1220006.1.5) \]

```Haskell
return ()
```


---
`( )` : "section" （セクション）
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-300003.5) \]

```Haskell
add1 = (1+)
```


---
`(,)` : the constructor for a tuple (タプルのコンストラクタ)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-360003.8) \]

```Haskell
f x y = liftM2 (,) x y 
```


---
`(, xxx)` : "TupleSections" （タプルセクション）
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#extension-TupleSections) \]

```Haskell
f xs = fmap (, True) xs
```


---
`(#  #)` : "unboxed tuple"
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#unboxed-tuples) \]

```Haskell
f x y = (# x+1, y-1 #)
```

---
`(# | | #)` : "unboxed sum"
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#unboxed-sums) \]

```Haskell
f :: (# Int | Bool | Char #) -> Int
f (# x | | #)    = 1
f (# | True | #) = 2
f _              = 3
```


---
`(..)` : exportリストでの名前の省略
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-1000005.2) \]

```Haskell
module GHC.Arr (
        Ix(..),
```


---
`(..)` : import宣言での名前の省略
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-1010005.3) \]

```Haskell
import GHC.Types (Bool(..))
```


---
`*` : 通常のデータ型を表すカインド (`Type`および``TYPE `LiftedRep``への別名)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-640004.1.1) \] \[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#the-kind) \] \[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#levity-polymorphism) \]

```Haskell
ghci> :kind Int
Int :: *
```


---
`->` : case expression (case式)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-460003.13) \]

```Haskell
f x = case x of
        Nothing -> False
        Just _  -> True
```


---
`->` : "view pattern" （ビューパターン）
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#view-patterns) \]

```Haskell
size (view -> Unit)        = 1
size (view -> Arrow t1 t2) = size t1 + size t2
```


---
`->` : "function type" (関数型)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-650004.1.2) \]

```Haskell
id :: a -> a
```


`.` : モジュール名を区切るドット
------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-180002.4) \]

```Haskell
import Data.Maybe
import qualified Text.Read.Lex as L

lexP = lift L.lex
```


`.` : universal quantification (全称量化子)
------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#explicit-universal-quantification-forall) \]

```Haskell
f :: forall a. a -> [a]
```

---
`:` : "list constructor" (リストのコンストラクタ)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-340003.7) \] \[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1200006.1.3) \] \[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-180002.4) \]

```Haskell
f x xs = x:xs
```


---
`:` : コロンで始まるシンボルはコンストラクタ
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-180002.4) \]

```Haskell
data NonEmpty a = a :| [a]
```


---
`::` : "type signature" (型シグネチャ)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-810004.4.1) \]

```Haskell
id :: a -> a
id x =  x
```


---
`::` : "expression type-signature" (type annotation) (式中での型シグネチャ (型注釈))
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-560003.16) \]

```Haskell
x = fromIntegral (maxBound::Int)
```


---
`;` : レイアウト規則におけるセミコロン
------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-210002.7) \]


```Haskell
f x = let a = 1; b = 2  
          g y = exp2  
      in exp1 
```


---
`<-` : lambda-bound in do expression (do式内でのラムダ変数の束縛)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-470003.14) \]

```Haskell
f = do
  x <- getLine
  putStrLn x
```


---
`<-` : "pattern guard" （パターンガード）
------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-830004.4.3) \]


```Haskell
f x
  | Just y <- g x = 
```


---
`=>` : context (type class constraint) (型クラスの制約)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-660004.1.3) \]

```Haskell
subtract :: (Num a) => a -> a -> a
subtract x y = y - x
```


---
`?` : "ImplicitParams" (暗黙の引数)
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#extension-ImplicitParams) \]

```Haskell
sort :: (?cmp :: a -> a -> Bool) => [a] -> [a]
sort = sortBy ?cmp
```


---
`@` : "as pattern" （アズパターン）
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-580003.17) \]

```Haskell
f s@(x:xs) = 
```


---
`@` : "type application" （型適用）
------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#extension-TypeApplications) \]

```Haskell
f = read @Int
```


---
`[]` : "empty list" (空のリスト)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-340003.7) \] \[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1200006.1.3) \]

```Haskell
null [] = True
null _  = False
```


---
`[ .. ]` : "arithmetic sequence" (算術シーケンスによるリスト表記)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-400003.10) \]

```Haskell
xs = [1..10]
```


---
`[ | <- ]` : "list comprehension" (リスト内包表記)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-420003.11) \]

```Haskell
xs = [x^2 | x <- [1..10]] 
```


---
`[|  |]` : Template Haskellのquote構文
------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#template-haskell) \]

```Haskell
add1 x = [| x + 1 |]
```


---
`[||  ||]` : Typed Template Haskellのquote構文
------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#template-haskell) \]

```Haskell
add1 x = [|| x + 1 ||]
```


---
`_` : "wildcard pattern" （ワイルドカードパターン）
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-580003.17) \]

```Haskell
f Red  =
f Blue =
f _    =
```


---
`_` : アンダースコアで始まる未使用の識別子
-------------------
\[ [GHC User’s Guide](http://downloads.haskell.org/~ghc/latest/docs/html/users_guide/using-warnings.html#ghc-flag--Wunused-binds) \] \[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-180002.4) \]

```Haskell
_w = True                -- No warning: _w starts with an underscore
```


---
`_` : "typed hole"
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#typed-holes) \]

```Haskell
sum xs = foldr _ 0 xs
```


---
`_` : "NumericUnderscores"
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#numeric-underscores) \]

```Haskell
million = 1_000_000
```


---
`\ ->` : "lambda abstraction" （ラムダ抽象）
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-260003.3) \]

```Haskell
add1 = \x -> x + 1
```


---
`\case ->` : "LambdaCase"
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#lambda-case) \]

```Haskell
f = \case
      Red  -> 2
      Blue -> 1
      _    -> 0
```


---
`` ` ` `` : "infix notation" （中置記法）
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-240003.2) \]

```Haskell
div10 x = x `div` 10
```


---
`{ }` : レイアウト規則における波括弧
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-210002.7) \]

```Haskell
f x = case x of {Nothing -> False; Just _ -> True}
```


---
`{ }` : "record syntax" (datatypes with field labels) (レコード構文)
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-490003.15) \]

```Haskell
data MyPoint = Point { x :: Int, y :: Int }
```


---
`{..}` : "record wildcard" （レコードワイルドカード）
------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#record-wildcards) \]

```Haskell
f Vec{..} = 
```


---
`{-#  #-}` : "compiler pragma" (コンパイラプラグマ)
------------------

\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch12.html#x19-18800012) \]
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#pragmas) \]
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#language-options) \]

```Haskell
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE GADTs            #-}

{-# INLINE fmap #-}
 ```

---
`|` : "boolean guard" (ブーリアンガード、または単純に、ガード)
------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-830004.4.3) \]

```Haskell
clip255 x
  | x > 255   = 255
  | otherwise = x 
```


---
`|` : "MultiWayIf"
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#multi-way-if-expressions) \]

```Haskell
if | x == ":q" -> quit
   | isError x -> errorExit x
   | otherwise -> execCommand x
```


`|` : algebraic datatype declaration (代数的データ型の宣言)
------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-690004.2.1) \]

```Haskell
data Maybe a = Nothing | Just a
```


---
`|` : "functional dependency" （関数従属）
------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#functional-dependencies) \]

```Haskell
class Foo a b c | a b -> c where 
```


---
`~` : "irrefutable pattern" （反駁不可パターン）
-------------------
\[ [Haskell 2010 Language Report](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-580003.17) \]

```Haskell
f1 ~(as,bs) =
```


---
`~` : "equality constraint"
-------------------
\[ [GHC User’s Guide](https://downloads.haskell.org/%7Eghc/latest/docs/html/users_guide/glasgow_exts.html#equality-constraints) \]

```Haskell
class (F a ~ b) => C a b where
```
　
　
以上です。