Noob在Haskell方面有困难-非范围内错误
我是Haskell的初学者,在获取由4个空列表组成的元组时遇到一些困难。下面的代码是我的Haskell程序的全部Noob在Haskell方面有困难-非范围内错误,haskell,Haskell,我是Haskell的初学者,在获取由4个空列表组成的元组时遇到一些困难。下面的代码是我的Haskell程序的全部 import Data.List import System.IO l = [] h = [] a = [] x = [] TextEditor = (l, h, a, x) backspace :: TextEditor -> TextEditor backspace (TextEditor l h a x) = (TextEditor(reverse (t
import Data.List
import System.IO
l = []
h = []
a = []
x = []
TextEditor = (l, h, a, x)
backspace :: TextEditor -> TextEditor
backspace (TextEditor l h a x) =
(TextEditor(reverse (tail (reverse l))) [] a x)
我犯了多个错误
Not in scope: data constructor ‘TextEditor’
Not in scope: type constructor 'TextEditor'
尽管谷歌搜索,我还是无法找出我的函数有什么问题。有人能帮我找到正确的方向吗?您在这里所做的是声明一个顶级作用域符号(如变量),名为
TextEditor
您可能要做的是声明一个TextEditor
数据类型及其对应的类型构造函数,可以这样做:
data TextEditor = TextEditor ([String], [String], [String], [String])
(您的定义可能会有所不同;您没有声明l
、h
、a
或x
的类型,所以我只是假设[String]
)
我建议您阅读中的
数据
声明和类型类定义。您在这里所做的是声明一个顶级作用域符号(如变量),称为TextEditor
您可能要做的是声明一个TextEditor
数据类型及其对应的类型构造函数,可以这样做:
data TextEditor = TextEditor ([String], [String], [String], [String])
(您的定义可能会有所不同;您没有声明l
、h
、a
或x
的类型,所以我只是假设[String]
)
我建议您阅读中的
数据
声明和类型类定义。我想您要做的是:
type L = [Char] -- aka String
type H = [Char]
type A = [Char]
type X = [Char]
data TextEditor = TextEditor L H A X -- You really should use more discriptive names
backspace :: TextEditor -> TextEditor
backspace (TextEditor l h a x) =
(TextEditor(reverse (tail (reverse l))) [] a x)
我猜你想做的是:
type L = [Char] -- aka String
type H = [Char]
type A = [Char]
type X = [Char]
data TextEditor = TextEditor L H A X -- You really should use more discriptive names
backspace :: TextEditor -> TextEditor
backspace (TextEditor l h a x) =
(TextEditor(reverse (tail (reverse l))) [] a x)
TextEditor
应该是类型还是某种值?在你的代码中,你将两者混合在一起,你不能这样做。reverse(tail(reverse l))
已经在模块Data.List
@chepner中定义为init
。我正在学习Haskell作为作业的一部分。令人烦恼的是,我们只允许使用head、tail、concatenate和dot操作符。谢谢你提供的信息!TextEditor
应该是类型还是某种值?在你的代码中,你将两者混合在一起,你不能这样做。reverse(tail(reverse l))
已经在模块Data.List
@chepner中定义为init
。我正在学习Haskell作为作业的一部分。令人烦恼的是,我们只允许使用head、tail、concatenate和dot操作符。谢谢你提供的信息!l
、h
、a
和x
的定义似乎不相关,只是不正确地试图将TextEditor
定义为包含四个列表的元组。正确;这就是我在回答中试图表达的意思。l
、h
、a
和x
的定义似乎是不相关的,只是不正确地试图将TextEditor
定义为一种包含四个列表的元组。正确;这就是我在回答中想要表达的。