如何在Haskell中获取字符的ASCII值? [英] How to get the ASCII value of a character in Haskell?

查看:163
本文介绍了如何在Haskell中获取字符的ASCII值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Haskell中字符的ASCII值?根据我阅读的内容

How to get the ASCII value of a character in Haskell? I've tried to use the ord function in GHCi, based on what I read here bug the the error message:

不在范围内:"ord"

Not in scope: `ord'

例如:

GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> ord 'a'

<interactive>:1:0: Not in scope: `ord'
Prelude>

我在做什么错了?

推荐答案

Travis Brown 所述,则必须从模块ord函数. rel ="noreferrer"> Data.Char :

As Travis Brown indicated in a comment, you have to import the ord function from the module Data.Char:

import Data.Char (ord)

main = print (ord 'a')

Prelude 模块是默认加载的,所有其他模块都必须显式导入.

Only the Prelude module is loaded by default, all other modules have to be imported explicitly.

这篇关于如何在Haskell中获取字符的ASCII值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆