如何获得ascii字符的值在haskell? [英] How to get ascii value of character in haskell?

查看:141
本文介绍了如何获得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:

http://haskell.org/ghc/docs/6.12。 2 / html / libraries / base-4.2.0.1 / Data-Char.html#6

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 函数 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.

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

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