and i found that the _mergeSort function was simply refusing
to compile... interpret... whatever...
It was complaining about the first line of code after the rev function
It wouldn't work unless one more parameter was added to
the _mergeSort function... one which _mergeSort doesnt ask for
sorry for the possibly terrible style issues.
I'm a java student at base and I'm just meddling trying to get things to work,
Now they work I'm screaming trying to figure out why.
cause they shouldnt work.
please do note, this code does work :P
**edit, simplified the split by adding _split
mergeSort [] = [] mergeSort [x] = [x] mergeSort x = _mergeSort (split x) [] -- <-problem is this empty array here --- I CANNOT figure out why the last empty string has decided to need to be here. --- my function doesnt ask for it....(see next line)... but it complains when ever it's ---taken away _mergeSort (x, y) = merge (mergeSort x, mergeSort y) [] --- merges two arrays together, putting the higher of the two head values in the results first merge (x:xs, y:ys) ls |x<=y = merge (x:xs, ys) (y:ls) |otherwise = merge (xs, y:ys) (x:ls) merge ([], y:ys) ls = merge ([], ys) (y:ls) merge (x:xs, []) ls = merge (xs, []) (x:ls) merge ([], []) ls = (rev' ls) --- <- noticed here I was using rev' rather than rev. changed it, ---now everything is sorting in the opposite direction (as i expected originally) --- and it now only compiles if the mystery empty bracket(my original problem) is removed... ---reverses values in an list rev l = rev' l [] rev' [] r = r rev' (x:xs) r = rev' xs (x:r) ---splits the array in two and returns them as a dual-array tuple split (x:y:ls) = split (x:y:ls) [] [] _split (x:y:ls) [] [] = split ls [x] [y] _split (x:y:ls) a b = split ls (x:a) (y:b) _split [x] a b = ((x:a), b) _split [] a b = (a, b)
**edit2** Umm ok, problem solved, but no less confused... I changed one of my functions and now everything is happy and cheerful, except the function has nothing to do with the original problem area..
should I dismiss as ghosts in the code?
Edited by Defenestrayte, 16 March 2011 - 11:11 PM.


Sign In
Create Account

Back to top









