0
votes

So I'm trying to create a bad sort function which, given a list, sorts it while deleting duplicates, and then pads the beginning of the list with "0s" to make sure the length of the badly sorted new list is the same as the size of the original list.

This is my code:

dodgySort4 xs = (replicate ((length xs) - (length (badQuick xs)) 0) : badQuick xs
  where
    badQuick  [] = []
    badQuick (x:xs) = (badQuick lesser) ++ [x] ++ (badQuick greater)
      where
          lesser  = filter (< x) xs
          greater = filter (> x) xs

However, I keep getting the "parse error on input ‘where’" error at the beginning of the first where and I'm not quite sure what the problem is?

1
@kennytm oh whoops that was a mistake i made while writing the question. the actual code doesn't have a new linereetyn
So there's no actual error? Or is there? By the way, your badQuick is really bad, it loses all values that are equal to x, e.g. badQuick [1,1,1,1,1,1,1] will be [1].Zeta
@Zeta no there is an error! i just accidentally added that new line when writing the code into the question. and yes haha, that's the purpose of the badQuick -- it deletes all duplicates, and that's why i pad the beginning with 0s so it's the same length as the original list... It's meant to feel a quickCheck that tests the property that length(xs) = length(dodgySort4(x)reetyn

1 Answers

2
votes

This is not about where, ) is not matched in replicate. The type is also mismatched, change : to ++ fix the issue.

dodgySort4 :: (Ord a, Num a) => [a] -> [a]
dodgySort4 xs = (replicate ((length xs) - (length (badQuick xs))) 0) ++ badQuick xs
  where ...