[Haskell-beginners] index too large
Nathan M. Holden
nathanmholden at gmail.com
Thu Nov 12 21:55:40 EST 2009
I've been working on a quick program that acts (vaguely) like a console, lets
me type notes and outputs them in a .tex file. I figure it's not that
complicated, but it uses a vaguely n-ary structure, so that I can have headers
and sub-notes, which loos like:
data Note = N {
nTitle :: {Char},
nBody :: {Char},
nFormat :: Format,
subs :: [Note]
| E [Char]
Format's just a collection of preset formats, so I don't have to dynamically
handle that (since I didn't need to for my uses).
Anyways, for whatever reason, sometimes while adding notes, it sends me an
error: Prelude.(!!): index too large
My only 2 uses of that are in
getFullName :: [Note] -> [Int] -> [Char]
getFullName d [] = "/"
getFullName d (x:xs) = "/" ++ getPartName (d!!x) ++ getFullName (subs (d!!x))
xs
and
moveIn :: [Note] -> [Int] -> [Char] -> Int -> [Int]
moveIn [] i m c = reverse i
moveIn ((N dt db df du):ds) [] m c = if matchNote (N dt db df du) m then c:[]
else moveIn ds [] m (c+1)
moveIn n i m c = last i : ((moveIn (subs (n!!(last i)))) (allButLast i) m 0)
where the [Int] is the variable I use to track where in the tree I am. Since
I'm not moving into a Note that doesn't exist, and the display shouldn't be
changing, what could be the problem?
This is probably too in-depth a question, now that I think about it...
More information about the Beginners
mailing list