Filtering a table using data constructors

I'm trying to learn Haskell and I have no idea how to continue from here. I added below the part of code that matters. So I defined a Query with multiple values, and the last one I got stuck one filters the rows in the table after a specific condition. So for example it filters the rows that only have the column "Final grade" > 5. I use FilterOp on each row to see if I can keep it or not, and my table only has Strings and Floats in it, so I made an instance for each one. After finishing the conditions I have to write the evaluation for the data constructor but I'm not sure that part is correct either. The input will be something like this: Filter (Gt "Final grade" (read "5" :: Float)) (FromCSV example_csv).

type CSV = String
type Table = [[String]]

data Query = FromCSV CSV
    | ToCSV Query
    ...
    | forall a. FEval a => Filter (FilterCondition a) Query
data FilterCondition a =
    Eq String a |
    Lt String a |
    Gt String a

type FilterOp = Row -> Bool

class FEval a where
    feval :: [String] -> (FilterCondition a) -> FilterOp

-- This is what I have to do
instance FEval Float where
    ...
instance FEval String where
    ...

-- I'm not sure this is right
instance Filter (FilterCondition a) Query where
    ...


Read more here: https://stackoverflow.com/questions/67376976/filtering-a-table-using-data-constructors

Content Attribution

This content was originally published by Biboni353 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: