Reputation:
I am a beginner with Haskell and having some difficulties getting a tuple consisting of 4 empty lists to work. The below code is the entirety of my Haskell Program.
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)
I get multiple errors.
Not in scope: data constructor ‘TextEditor’
Not in scope: type constructor 'TextEditor'
Despite googling I can't work out what's wrong with my functions. Could someone help push me in the right direction please?
Upvotes: 0
Views: 107
Reputation: 120751
I guess what you're trying to do is this:
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)
Upvotes: 2
Reputation: 14520
What you've done here is declared a top-level scoped symbol (like a variable) called TextEditor
.
What you probably want to do is to declare a TextEditor
data type and its corresponding type constructor, which might be done like this:
data TextEditor = TextEditor ([String], [String], [String], [String])
(Your definition may vary; you didn't declare the types of l
, h
, a
or x
so I'm just assuming [String]
)
I'd recommend reading up about data
declarations and typeclass definitions in the appropriate LYAH chapter.
Upvotes: 1