I wrote a function with Haskell to extract some values from this data type :
data Result = ResuVal Double
| ResuValIdx Double (Maybe Int)
| ResuValCpt Double Int
| NoResu
deriving (Show)
This function extract the Int values in the Result data type and concatenate them in a list.
catIdxCpt :: [Result] -> [Int]
catIdxCpt [] = []
catIdxCpt (x:xs) = case x of
ResuValIdx v (Just i) -> i:catIdxCpt xs
ResuValCpt v c -> c:catIdxCpt xs
_ -> catIdxCpt xs
This function is working well but I first tried to wrote it with a comprehension list such as :
catIdxCpt ls = [i | ResuValIdx v (Just i) <- ls ]
or
catIdxCpt ls = [i | ResuValIdx v (Just i) <- ls | ResuValCpt v i <- ls ]
and other combinations. But I didn't managed to have the expected result.
Do you know how to built (if it is possible) the catIdxCpt function with a list comprehension ?
[i | ... | ... ]) can actually be used tozipWithNseveral lists via theParallelListComprehensionextension. Doesn't help here, but it has its uses.