Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 使用NoImplicitPrelude重新绑定数值文本的语法_Haskell_Syntax_Ghc - Fatal编程技术网

Haskell 使用NoImplicitPrelude重新绑定数值文本的语法

Haskell 使用NoImplicitPrelude重新绑定数值文本的语法,haskell,syntax,ghc,Haskell,Syntax,Ghc,看来我对ghci中的-XNoImplicitPrelude标志的理解是错误的,对此我感到非常困惑 警察说 整数文本368表示“fromInteger(368::integer)”,而不是“Prelude.fromInteger(368::integer)” 但是,当我加载此代码时: {-# LANGUAGE NoImplicitPrelude #-} module Try where import Prelude (Float,Integer, realToFrac) data MyNum =

看来我对ghci中的-XNoImplicitPrelude标志的理解是错误的,对此我感到非常困惑

警察说

整数文本368表示“fromInteger(368::integer)”,而不是“Prelude.fromInteger(368::integer)”

但是,当我加载此代码时:

{-# LANGUAGE NoImplicitPrelude #-}
module Try where
import Prelude (Float,Integer, realToFrac)
data MyNum = Nummy Float
fromInteger :: Integer -> MyNum 
fromInteger x = Nummy (realToFrac x)
进入ghci,我得到以下信息:

~/tmp$ ghci -XNoImplicitPrelude try.hs 
[1 of 1] Compiling Try              ( try.hs, interpreted )
Ok, modules loaded: Try.
*Try> 4
4
当我期望得到:

*Try> 4
Nummy 4.0
*Try> 

类似的事情发生在Try模块内部;例如,当我声明一个函数返回类型MyNum并将其定义为整数文本时,出现了一个类型错误。

您链接到的文档说,必须启用
重新绑定语法扩展才能工作。

谢谢,我想知道为什么没有人问过这个问题。我想我需要在手背上纹上“RTFM”。