本文介绍了如何获得ascii字符的值在haskell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是想知道如何获得ascii字符的值在haskell?
我试图在ghci中使用'ord'函数,基于我在这里读取:
Just wondering how to get ascii value of character in haskell?I've tried to use the 'ord' function in ghci, based on what i read here:
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>
我做错了什么?
推荐答案
由于在评论中指出,您必须导入 ord
函数:
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')
只有模块默认加载,所有其他模块必须显式导入。
Only the Prelude
module is loaded by default, all other modules have to be imported explicitly.
这篇关于如何获得ascii字符的值在haskell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!