Im trying to order a list of a custom datatype with different size of atributes to validate if the datatype format is true but I don't know how to manipulate it by using quick sort.
The datatype:
data Cuidado = Comprar String Int | Medicar String
I'm testing pattern matching with quicksort but it doesnt make any sense.
valCui :: [Cuidado] -> [Cuidado]
valCui [] = []
valCui (x:xs) = valCui [a | a <- xs, x > a] ++ [x] ++ valCui [a | a <- xs, x <= a]
Output is supposed to be:
valCui [Medicar med7, Comprar med4 30] == [Comprar med4 30, Medicar med7]
There are only two small problems here:
You have a
->operator in your list comprehension. Presumably you mean to check the greater-than relation here, but the operator for that is just>. The->arrow is special syntax, reserved for function signatures, lambdas andcaseassignments.In order to be able to use such comparison operators on your custom data type, you need it to have an instance of the
Ordtypeclass. But yours doesn't, or at least you didn't show it. The easiest way to get such an instance is to derive it: