LoginSignup
56
48

More than 1 year has passed since last update.

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

Last updated at Posted at 2018-06-01

【追記】(2021/12/25)

2021/12/25時点で、このページの内容は古くなっています。
新しい内容は以下でメンテナンスを継続していますので、そちらを参照して下さい。
英語版はこちら日本語版はこちらです。

はじめに

このページは、Haskell/GHCにおける記号の検索を支援するためのリファレンス集です。
(オリジナルはGitHubのこちらですが、日本語でも検索しやすいようにQiitaにも載せておきます。)

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

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

それでは、Happy Haskelling!


! : "strictness flag" (正格性フラグ)

[ Haskell 2010 Language Report ]

data Vec = Vec !Int

! : "bang pattern" (バンパターン)

[ GHC User’s Guide ]

f1 !x = 

# : "MagicHash"

[ GHC User’s Guide ]

data Int = I# Int#

# : "OverloadedLabels"

[ GHC User’s Guide ]

example = #x (Point 1 2)

# : Cプリプロセッサのディレクティブ

[ GHC User’s Guide ]

#include "MachDeps.h"

# : hsc2hsコマンドのオペレータ

[ GHC User’s Guide ]

flag = #const VER_MAJORVERSION

$( ) : Template Haskellのsplice構文

[ GHC User’s Guide ]

two = $(add1 1)

$$( ) : Typed Template Haskellのsplice構文

[ GHC User’s Guide ]

two = $$(add1 1)

' : 識別子の構成文字としてのシングルクォート

[ Haskell 2010 Language Report ]

xs' = f ys

' : 昇格されたコンストラクタ(promoted constructors)のプレフィクス

[ GHC User’s Guide ]

type * = TYPE 'LiftedRep

' '' : Template Haskellのquote構文

[ GHC User’s Guide ]

makeLenses ''FooBar

() : "unit type" (ユニット型)

[ Haskell 2010 Language Report ] [ Haskell 2010 Language Report ]

main :: IO ()

() : "unit expression" (値としてのユニット)

[ Haskell 2010 Language Report ] [ Haskell 2010 Language Report ]

return ()

( ) : "section" (セクション)

[ Haskell 2010 Language Report ]

add1 = (1+)

(,) : the constructor for a tuple (タプルのコンストラクタ)

[ Haskell 2010 Language Report ]

f x y = liftM2 (,) x y 

(, xxx) : "TupleSections" (タプルセクション)

[ GHC User’s Guide ]

f xs = fmap (, True) xs

(# #) : "unboxed tuple"

[ GHC User’s Guide ]

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

(# | | #) : "unboxed sum"

[ GHC User’s Guide ]

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

(..) : exportリストでの名前の省略

[ Haskell 2010 Language Report ]

module GHC.Arr (
        Ix(..),

(..) : import宣言での名前の省略

[ Haskell 2010 Language Report ]

import GHC.Types (Bool(..))

* : 通常のデータ型を表すカインド (TypeおよびTYPE `LiftedRepへの別名)

[ Haskell 2010 Language Report ] [ GHC User’s Guide ] [ GHC User’s Guide ]

ghci> :kind Int
Int :: *

-> : case expression (case式)

[ Haskell 2010 Language Report ]

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

-> : "view pattern" (ビューパターン)

[ GHC User’s Guide ]

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

-> : "function type" (関数型)

[ Haskell 2010 Language Report ]

id :: a -> a

. : モジュール名を区切るドット

[ Haskell 2010 Language Report ]

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

lexP = lift L.lex

. : universal quantification (全称量化子)

[ GHC User’s Guide ]

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

: : "list constructor" (リストのコンストラクタ)

[ Haskell 2010 Language Report ] [ Haskell 2010 Language Report ] [ Haskell 2010 Language Report ]

f x xs = x:xs

: : コロンで始まるシンボルはコンストラクタ

[ Haskell 2010 Language Report ]

data NonEmpty a = a :| [a]

:: : "type signature" (型シグネチャ)

[ Haskell 2010 Language Report ]

id :: a -> a
id x =  x

:: : "expression type-signature" (type annotation) (式中での型シグネチャ (型注釈))

[ Haskell 2010 Language Report ]

x = fromIntegral (maxBound::Int)

; : レイアウト規則におけるセミコロン

[ Haskell 2010 Language Report ]

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

<- : lambda-bound in do expression (do式内でのラムダ変数の束縛)

[ Haskell 2010 Language Report ]

f = do
  x <- getLine
  putStrLn x

<- : "pattern guard" (パターンガード)

[ Haskell 2010 Language Report ]

f x
  | Just y <- g x = 

=> : context (type class constraint) (型クラスの制約)

[ Haskell 2010 Language Report ]

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

? : "ImplicitParams" (暗黙の引数)

[ GHC User’s Guide ]

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

@ : "as pattern" (アズパターン)

[ Haskell 2010 Language Report ]

f s@(x:xs) = 

@ : "type application" (型適用)

[ GHC User’s Guide ]

f = read @Int

[] : "empty list" (空のリスト)

[ Haskell 2010 Language Report ] [ Haskell 2010 Language Report ]

null [] = True
null _  = False

[ .. ] : "arithmetic sequence" (算術シーケンスによるリスト表記)

[ Haskell 2010 Language Report ]

xs = [1..10]

[ | <- ] : "list comprehension" (リスト内包表記)

[ Haskell 2010 Language Report ]

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

[| |] : Template Haskellのquote構文

[ GHC User’s Guide ]

add1 x = [| x + 1 |]

[|| ||] : Typed Template Haskellのquote構文

[ GHC User’s Guide ]

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

_ : "wildcard pattern" (ワイルドカードパターン)

[ Haskell 2010 Language Report ]

f Red  =
f Blue =
f _    =

_ : アンダースコアで始まる未使用の識別子

[ GHC User’s Guide ] [ Haskell 2010 Language Report ]

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

_ : "typed hole"

[ GHC User’s Guide ]

sum xs = foldr _ 0 xs

_ : "NumericUnderscores"

[ GHC User’s Guide ]

million = 1_000_000

\ -> : "lambda abstraction" (ラムダ抽象)

[ Haskell 2010 Language Report ]

add1 = \x -> x + 1

\case -> : "LambdaCase"

[ GHC User’s Guide ]

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

` ` : "infix notation" (中置記法)

[ Haskell 2010 Language Report ]

div10 x = x `div` 10

{ } : レイアウト規則における波括弧

[ Haskell 2010 Language Report ]

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

{ } : "record syntax" (datatypes with field labels) (レコード構文)

[ Haskell 2010 Language Report ]

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

{..} : "record wildcard" (レコードワイルドカード)

[ GHC User’s Guide ]

f Vec{..} = 

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

[ Haskell 2010 Language Report ]
[ GHC User’s Guide ]
[ GHC User’s Guide ]

{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE GADTs            #-}

{-# INLINE fmap #-}

| : "boolean guard" (ブーリアンガード、または単純に、ガード)

[ Haskell 2010 Language Report ]

clip255 x
  | x > 255   = 255
  | otherwise = x 

| : "MultiWayIf"

[ GHC User’s Guide ]

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

| : algebraic datatype declaration (代数的データ型の宣言)

[ Haskell 2010 Language Report ]

data Maybe a = Nothing | Just a

| : "functional dependency" (関数従属)

[ GHC User’s Guide ]

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

~ : "irrefutable pattern" (反駁不可パターン)

[ Haskell 2010 Language Report ]

f1 ~(as,bs) =

~ : "equality constraint"

[ GHC User’s Guide ]

class (F a ~ b) => C a b where

 
 
以上です。
 
 
 

56
48
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
56
48