Haskell中的单引号和双引号

编程入门 行业动态 更新时间:2024-10-27 06:33:28
本文介绍了Haskell中的单引号和双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

考虑:

ghci> :t'a''a':: Char ghci> :taa:: [Char]

为什么要治疗单引号和双引号的区别是不同的,并且是那么重要?解析方案

这与C / C ++ / C#/ Java和其他编程语言。单引号表示单字符,双引号表示字符数组(字符串)。

在Haskell中,'c'是一个字符( Char )和c是一个字符列表( [您可以将此与整数和整数列表进行比较: pre> ghci的>让a = 1 ghci>让b = [1,2,3] ghci> :t a a :: Integer ghci> :tb b :: [Integer]

这很重要,因为必须有一个区别单个元素和元素列表之间。您可以对简单元素执行不同的操作,并对列表执行不同的操作。

Consider:

ghci> :t 'a' 'a' :: Char ghci> :t "a" "a" :: [Char]

Why is it treating single and double quotes differently, and is that important?

解决方案

This is just like C/C++/C#/Java and other programming languages. Single quotes means single character, double quotes means character array (string).

In Haskell, 'c' is a single character (Char), and "c" is a list of characters ([Char]).

You can compare this to integers and lists of integers:

ghci> let a = 1 ghci> let b = [1,2,3] ghci> :t a a :: Integer ghci> :t b b :: [Integer]

It is important because there has to be a distinction between single elements and a list of elements. You can perform different operations on simple elements, and different operations on lists.

更多推荐

Haskell中的单引号和双引号

本文发布于:2023-10-10 11:32:10,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单引号   双引号   Haskell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!