• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

takenobu-hs/haskell-symbol-search-cheatsheet: Haskell/GHC symbol search cheatshe ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

takenobu-hs/haskell-symbol-search-cheatsheet

开源软件地址(OpenSource Url):

https://github.com/takenobu-hs/haskell-symbol-search-cheatsheet

开源编程语言(OpenSource Language):


开源软件介绍(OpenSource Introduction):

Haskell/GHC symbol search cheatsheet

Several features of Haskell/GHC have low googleability. Because some of them are composed of symbols :)
This page is a reference collection to support search of them.

If you want to search for function symbols like ., $, >>=, <*>, ..., you can use the following search engines:

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 pre-processor's directive

[ GHC User's Guide ]

#include "MachDeps.h"

# : hsc2hs command's operator

[ GHC User's Guide ]

flag = #const VER_MAJORVERSION

$( ) : Template Haskell’s splice syntax

[ GHC User's Guide ]

two = $(add1 1)

$$( ) : Typed Template Haskell’s splice syntax

[ GHC User's Guide ]

two = $$(add1 1)

%1 -> : "Linear types"

[ GHC User's Guide ]

f :: a %1 -> a 

' : an identifier consists of a letter followed by zero or more letters, digits, underscores, and single quotes

[ Haskell 2010 Language Report ]

xs' = f ys

' : promoted constructors are prefixed by a tick '

[ GHC User's Guide ]

type * = TYPE 'LiftedRep

' '' : Template Haskell’s quotation syntax

[ 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" - a convenient syntax for partial application

[ 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 all of its names

[ Haskell 2010 Language Report ]

module GHC.Arr (
        Ix(..),

(..) : import all of its names

[ Haskell 2010 Language Report ]

import GHC.Types (Bool(..))

* : the kind of ordinary types (synonym for Type and TYPE `LiftedRep)

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

ghci> :kind Int
Int :: *

-> : case expression

[ 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

. : module names are a dot-separated sequence

[ Haskell 2010 Language Report ]

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

lexP = lift L.lex

. : "OverloadedRecordDot"

[ GHC User's Guide ]

getResult c = c.result

getResults = map (.result)

. : "OverloadedRecordUpdate" (experimental)

[ GHC User's Guide ]

setYearTaken c y = c{taken.year = y}

. : universal quantification

[ GHC User's Guide ]

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

: : "list constructor" (cons)

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

f x xs = x:xs

: : an operator symbol starting with a colon is a constructor

[ 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)

; : semicolon in layout rule

[ Haskell 2010 Language Report ]

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

<- : lambda-bound in do expression

[ 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" (nil)

[ 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]] 

[| |], [e| |], [d| |], [t| |], [p| |] : Template Haskell’s quotation syntax (expression, declaration, type, and pattern)

[ GHC User's Guide ]

add1 x = [| x + 1 |]

[varid| |] : Template Haskell’s quasi-quotation syntax

[ GHC User's Guide ]

greet name = [interpolate| Hello, #name! |]

[|| ||] : Typed Template Haskell’s quotation syntax

[ GHC User's Guide ]

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

_ : "wildcard pattern"

[ Haskell 2010 Language Report ]

f Red  =
f Blue =
f _    =

_ : unused identifiers beginning with underscore

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

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

_ : "typed hole" (expression level)

[ GHC User's Guide ]

sum xs = foldr _ 0 xs

_ : "type wildcard" (type level)

[ GHC User's Guide ]

not'  

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap