118代表什么意思| 茴三硫片主治什么| exp是什么函数| zoe是什么意思| 额头和下巴长痘痘是什么原因| 剁椒鱼头属于什么菜系| 橘络的功效与作用是什么| 97年属什么的生肖| 什么茶可以减肥| 小孩走路迟是什么原因| 中暑为什么不能打点滴| 睡久了头疼是什么原因| 肚子疼呕吐是什么原因引起的| 401什么意思| 脂溢性皮炎吃什么药| 肘是什么意思| 粤语什么怎么说| 跳楼机是什么| 北极熊代表什么生肖| 秃鹫是什么动物| 经常呕吐是什么原因| 宫颈多发潴留囊肿是什么意思| 屏保是什么| 画是什么结构| 月经不来什么原因| 突然好想你你会在哪里是什么歌| 安宫牛黄丸什么时候吃最好| 临界心电图是什么意思| 左眼屈光不正是什么意思| 土字旁有什么字| 早起嘴巴苦什么原因| 为什么今年夏天特别热| 电压是什么意思| 女人自尊心强说明什么| 血压高有什么表现| 什么是真菌感染| 洗衣机脱水是什么意思| 男士私处瘙痒用什么药| 空调病是什么| 纺织厂是做什么的| 女人脸肿是什么原因引起的| 钱串子进屋有什么预兆| 你什么都没看见| 正月二十一是什么星座| 3月15号是什么星座| 什么是性| 种小麦用什么肥料好| 劫财是什么意思| 拿什么证明分居两年| 个人solo什么意思| 五七是什么意思有什么讲究| 小孩缺铁有什么症状| 发热出汗是什么原因| 葫芦挂在家里什么位置好| 潦倒是什么意思| 狮子座什么性格| cj是什么| 鲨鱼是什么动物| 小猪佩奇为什么这么火| 什么眼霜好| 肌酐高有什么危害| 繁衍的衍是什么意思| 凤毛麟角什么意思| 什么食物含蛋白质高| 礽是什么意思| 南宁有什么好吃的| 农历六月十二是什么日子| 什么欢快| 灵长类是什么意思| 眼皮红肿是什么原因引起的| 生菜为什么会苦| 手工diy是什么意思| 柔软的近义词是什么| cc是什么牌子| 褙子是什么| 怀孕后不能吃什么| 无名指下面的竖线代表什么| 肾素低说明什么| 流产有什么症状| 俄罗斯的货币叫什么| 盆腔积液有什么症状| 女人脚发热是什么原因| 什么才是真正的情人| 南方是什么生肖| 县副局长是什么级别| 什么食物降火| 专硕和学硕有什么区别| 喉结肿大是什么原因| 人加一笔变成什么字| 七月七是什么日子| 梦到跟人吵架是什么意思| 去美容院洗脸有什么好处| gag是什么意思| 南极为什么比北极冷| 鱼的五行属什么| 2020是什么年| 淀粉样变是什么病| 什么叫肺大泡| 什么西瓜好吃| 日语亚麻得是什么意思| 肚脐上方是什么器官| 副军长是什么军衔| 西布曲明的危害及副作用分别是什么| 言谈举止是什么意思| 手麻木什么原因| complex是什么意思| 为什么不建议吃大豆油| 胃左边疼是什么原因| 稷字五行属什么| 高血压挂什么科| 主动脉硬化是什么意思| 三十八岁属什么生肖| 脑鸣是什么原因引起的| leu是什么氨基酸| 盆腔炎要做什么检查| 降压药什么药好| 关节积液是什么原因造成的| 血管造影是什么检查| cma检测是什么| 丹凤朝阳什么意思| 舌苔开裂是什么原因呢| 23是什么生肖| 皓是什么意思| 文化底蕴是什么意思| 面瘫吃什么药| 场所是什么意思| 2010年是什么年| 颔是什么部位| 过劳肥是什么意思| 有所作为的意思是什么| 观音菩萨叫什么名字| 飞蛾吃什么东西| 大便失禁是什么原因| 好奇害死猫什么意思| 吃什么可以降血压| 清洁度lv是什么意思| 90年属什么的生肖| 喂母乳不能吃什么| 88年是什么命| 硬皮病是什么病| r级电影是什么意思| 肿瘤病人不能吃什么| 樵夫是什么生肖| 亚麻籽油和胡麻油有什么区别| 豆腐吃多了有什么坏处| 属虎适合佩戴什么饰品| 三油甘脂是什么| 呵呵什么意思| 恶心是什么意思| 黑道日为什么还是吉日| qid医学上是什么意思| 火龙果和香蕉榨汁有什么功效| 什么的果子| 生是什么意思| 大快朵颐是什么意思| 越来越什么| 枸杞配什么壮阳| 什么的色彩| 通勤什么意思| 孕期头晕是什么原因| 人工周期是什么意思| 百忧解是什么药| 头疼挂什么科| 总胆汁酸高是什么意思| 结膜水肿用什么眼药水| 不想吃饭没胃口是什么原因| 电轴左偏是什么原因| 胃癌挂什么科| 佟丽娅为什么离婚| who是什么意思| 嬗变什么意思| 豆浆和什么不能一起吃| 县副局长是什么级别| 个人简历籍贯填什么| 框镜鱼是什么鱼| 优对什么| 为什么老被蚊子咬| nba季后赛什么时候开始| 白细胞增多是什么原因| 宫颈肥大伴纳氏囊肿是什么意思| 大张伟的真名叫什么| 土中金是什么生肖| 波罗蜜多什么意思| 竹笋炒什么好吃| 太阳为什么能一直燃烧| 脚背浮肿是什么原因引起的| 处女座上升星座是什么| pmi是什么| 结甲可能是什么意思| 艾滋病的症状是什么| 凌晨两点是什么时辰| 刷酸是什么| 舌苔发黑是什么原因| 小孩呕吐是什么原因| 拉条子是什么意思| 小腿前侧肌肉叫什么| 拉黑屎是什么原因| 尿酸高吃什么水果| 什么叫精索静脉曲张啊| 子宫形态失常是什么意思| 诸事顺遂是什么意思| 什么原因造成高血压| 出汗有盐霜是什么原因| 婴儿拉肚子是什么原因造成的| 消化内科主要看什么病| 弛张热常见于什么病| 为什么打雷闪电| 左眼跳财是什么意思| 肝胆相照什么意思| 射手座是什么性格| 气短咳嗽是什么原因引起的| 石女是什么意思啊| 狮子的天敌是什么动物| 吃什么补孕酮| 站姐是什么职业| 好无奈是什么意思| l是什么码| 赵云的马叫什么| 右肩膀和胳膊疼痛是什么原因| 维生素b2有什么功效| 脍炙人口是什么意思| 宿便是什么意思| 澳门有什么好玩的| 大姨妈提前是什么原因| 毛子是什么意思| 10月30号是什么星座| 前三个月怀孕注意什么| 昆明有什么好吃的| 种植牙有什么危害| 空调开不了机是什么原因| 今天开什么奖| 解尿支原体是什么| 非淋菌尿道炎用什么药| 五心烦热是什么症状| 皮肤科挂什么科| 迷你巴拉巴拉和巴拉巴拉什么关系| 区武装部部长是什么级别| 什么叫假性发烧| 催乳素过高是什么原因| 七月十日是什么日子| 不还信用卡有什么后果| 鸡冠油是什么| 贵字五行属什么| 小孩出汗多是什么原因| 温州冬至吃什么| 吃什么壮阳| 干戈是什么意思| 钢镚是什么意思| 本科和专科是什么意思| 大饼是什么意思| 儿童说话晚去医院挂什么科| 为什么六月腊月不搬家| 性生活出血是什么原因| 蟋蟀是靠什么发声的| 痛风是什么原因引起的| 一个月没有来月经是什么原因| 吃鱼有什么好处| 胸围98是什么罩杯| 翊字五行属什么| 黄皮不能和什么一起吃| 嬛嬛一袅楚宫腰什么意思| 老是咳嗽挂什么科| 暂时无法接通是什么意思| 氩气是什么气体| 百度

Appendix?B.?Characters, strings, and escaping rules

Table of Contents

Writing character and string literals
International language support
Escaping text
Single-character escape codes
Multiline string literals
ASCII control codes
Control-with-character escapes
Numeric escapes
The zero-width escape sequence

This appendix covers the escaping rules used to represent non-ASCII characters in Haskell character and string literals. Haskell's escaping rules follow the pattern established by the C programming language, but expand considerably upon them.

Writing character and string literals

A single character is surrounded by ASCII single quotes, ', and has type Char.

ghci> 'c'
'c'
ghci> :type 'c'
'c' :: Char

A string literal is surrounded by double quotes, ", and has type [Char] (more often written as String).

ghci> "a string literal"
"a string literal"
ghci> :type "a string literal"
"a string literal" :: [Char]

The double-quoted form of a string literal is just syntactic sugar for list notation.

ghci> ['a', ' ', 's', 't', 'r', 'i', 'n', 'g'] == "a string"
True

International language support

Haskell uses Unicode internally for its Char data type. Since String is just an alias for [Char], a list of Chars, Unicode is also used to represent strings.

Different Haskell implementations place limitations on the character sets they can accept in source files. GHC allows source files to be written in the UTF-8 encoding of Unicode, so in a source file, you can use UTF-8 literals inside a character or string constant. Do be aware that if you use UTF-8, other Haskell implementations may not be able to parse your source files.

When you run the ghci interpreter interactively, it may not be able to deal with international characters in character or string literals that you enter at the keyboard.

[Note]Note

Although Haskell represents characters and strings internally using Unicode, there is no standardised way to do I/O on files that contain Unicode data. Haskell's standard text I/O functions treat text as a sequence of 8-bit characters, and do not perform any character set conversion.

There exist third-party libraries that will convert between the many different encodings used in files and Haskell's internal Unicode representation.

Escaping text

Some characters must be escaped to be represented inside a character or string literal. For example, a double quote character inside a string literal must be escaped, or else it will be treated as the end of the string.

Single-character escape codes

Haskell uses essentially the same single-character escapes as the C language and many other popular languages.

Table?B.1.?Single-character escape codes

EscapeUnicodeCharacter
\0U+0000null character
\aU+0007alert
\bU+0008backspace
\fU+000Cform feed
\nU+000Anewline (line feed)
\rU+000Dcarriage return
\tU+0009horizontal tab
\vU+000Bvertical tab
\"U+0022double quote
\&n/aempty string
\'U+0027single quote
\\U+005Cbackslash

Multiline string literals

To write a string literal that spans multiple lines, terminate one line with a backslash, and resume the string with another backslash. An arbitrary amount of whitespace (of any kind) can fill the gap between the two backslashes.

"this is a \
	\long string,\
    \ spanning multiple lines"

ASCII control codes

Haskell recognises the escaped use of the standard two- and three-letter abbreviations of ASCII control codes.

Table?B.2.?ASCII control code abbreviations

EscapeUnicodeMeaning
\NULU+0000null character
\SOHU+0001start of heading
\STXU+0002start of text
\ETXU+0003end of text
\EOTU+0004end of transmission
\ENQU+0005enquiry
\ACKU+0006acknowledge
\BELU+0007bell
\BSU+0008backspace
\HTU+0009horizontal tab
\LFU+000Aline feed (newline)
\VTU+000Bvertical tab
\FFU+000Cform feed
\CRU+000Dcarriage return
\SOU+000Eshift out
\SIU+000Fshift in
\DLEU+0010data link escape
\DC1U+0011device control 1
\DC2U+0012device control 2
\DC3U+0013device control 3
\DC4U+0014device control 4
\NAKU+0015negative acknowledge
\SYNU+0016synchronous idle
\ETBU+0017end of transmission block
\CANU+0018cancel
\EMU+0019end of medium
\SUBU+001Asubstitute
\ESCU+001Bescape
\FSU+001Cfile separator
\GSU+001Dgroup separator
\RSU+001Erecord separator
\USU+001Funit separator
\SPU+0020space
\DELU+007Fdelete

Control-with-character escapes

Haskell recognises an alternate notation for control characters, which represents the archaic effect of pressing the control key on a keyboard and chording it with another key. These sequences begin with the characters \^, followed by a symbol or uppercase letter.

Table?B.3.?Control-with-character escapes

EscapeUnicodeMeaning
\^@U+0000null character
\^A through \^ZU+0001 through U+001Acontrol codes
\^[U+001Bescape
\^\U+001Cfile separator
\^]U+001Dgroup separator
\^^U+001Erecord separator
\^_U+001Funit separator

Numeric escapes

Haskell allows Unicode characters to be written using numeric escapes. A decimal character begins with a digit, e.g. \1234. A hexadecimal character begins with an x, e.g. \xbeef. An octal character begins with an o, e.g. \o1234.

The maximum value of a numeric literal is \1114111, which may also be written \x10ffff or \o4177777.

The zero-width escape sequence

String literals can contain a zero-width escape sequence, written \&. This is not a real character, as it represents the empty string.

ghci> "\&"
""
ghci> "foo\&bar"
"foobar"

The purpose of this escape sequence is to make it possible to write a numeric escape followed immediately by a regular ASCII digit.

ghci> "\130\&11"
"\130\&11"

Because the empty escape sequence represents an empty string, it is not legal in a character literal.

Want to stay up to date? Subscribe to the comment feed for this chapter, or the entire book.

Copyright 2007, 2008 Bryan O'Sullivan, Don Stewart, and John Goerzen. This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 License. Icons by Paul Davey aka Mattahan.

吃绿豆有什么好处 甲状腺素高是什么原因 浙江大学什么专业最好 灰蓝色是什么颜色 拉肚子吃什么食物
热锅上的蚂蚁是什么意思 锴字五行属什么 1956年属什么生肖 7月15是什么星座的 事宜是什么意思
惊蛰后是什么节气 宝宝反复发烧是什么原因 属狗和什么属相不合 什么样的柳树 中秋节为什么要吃月饼
百米12秒什么水平 抬头头晕是什么原因 吃鸡蛋胃疼是什么原因 吡唑醚菌酯治什么病 无济于事的济是什么意思
兰花是什么季节开的kuyehao.com 电饭煲内胆什么材质好hcv8jop0ns4r.cn 氯化钠是什么盐hlguo.com 女人性高潮是什么感觉hcv7jop7ns3r.cn 备孕男性吃什么精子强hcv8jop6ns6r.cn
汉族人是什么人种hcv8jop9ns8r.cn 血浓稠是什么原因引起的hcv9jop1ns3r.cn 食用葡萄糖是什么hcv8jop0ns4r.cn darker是什么意思aiwuzhiyu.com 降7是什么调hcv8jop4ns0r.cn
青霉素主治什么病hcv7jop6ns2r.cn 脑梗塞用什么药效果好hcv8jop5ns3r.cn 口臭要做什么检查hcv8jop0ns1r.cn 风湿性心脏病是什么原因引起的hcv9jop4ns4r.cn 嗳气是什么症状xinmaowt.com
内膜薄是什么意思hcv7jop6ns1r.cn 号外是什么意思hcv7jop6ns1r.cn 免是什么意思naasee.com 鼻子有痣代表什么hcv7jop7ns1r.cn 子宫肌瘤有什么症状表现hcv9jop7ns9r.cn
百度 技术支持:克隆侠蜘蛛池 www.kelongchi.com