
Hello, I need to parse a commande line which allows user to describe indices like this 1 -> only one indice 1-5 -> [1..5] 1-5 6-10 ...-> [1..5] ++ [6..10] My question is what it the best type in order to store this information ? Range Int = Range Int | RangeFromTo Int Int | Range Int <+> Range Int At some point I would like to add the possibility to have multiples Indices with the ',' 1,3,5 -> [1,3,5] list of indices This type is used at some point as a List. My question is, are you aware of a similar type in the standar library. This is the kind of information tahth w should parse when we request to print pages. (list of pages to print). Cheers Frederic

Sounds like you want something along the lines of https://hackage.haskell.org/package/data-interval Which has types for open/closed intervals and sets/maps of them. Cheers, Merijn
On 4 Oct 2021, at 15:26, PICCA Frederic-Emmanuel
wrote: Hello, I need to parse a commande line which allows user to describe indices like this
1 -> only one indice 1-5 -> [1..5] 1-5 6-10 ...-> [1..5] ++ [6..10]
My question is what it the best type in order to store this information ?
Range Int = Range Int | RangeFromTo Int Int | Range Int <+> Range Int
At some point I would like to add the possibility to have multiples Indices with the ',' 1,3,5 -> [1,3,5] list of indices
This type is used at some point as a List.
My question is, are you aware of a similar type in the standar library. This is the kind of information tahth w should parse when we request to print pages. (list of pages to print).
Cheers
Frederic
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

List of tuples, map then zip, or in Rust enumerate… Greets,branimir.
On 04.10.2021., at 15:26, PICCA Frederic-Emmanuel
wrote: Hello, I need to parse a commande line which allows user to describe indices like this
1 -> only one indice 1-5 -> [1..5] 1-5 6-10 ...-> [1..5] ++ [6..10]
My question is what it the best type in order to store this information ?
Range Int = Range Int | RangeFromTo Int Int | Range Int <+> Range Int
At some point I would like to add the possibility to have multiples Indices with the ',' 1,3,5 -> [1,3,5] list of indices
This type is used at some point as a List.
My question is, are you aware of a similar type in the standar library. This is the kind of information tahth w should parse when we request to print pages. (list of pages to print).
Cheers
Frederic
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

On Mon, 4 Oct 2021, PICCA Frederic-Emmanuel wrote:
Hello, I need to parse a commande line which allows user to describe indices like this
1 -> only one indice 1-5 -> [1..5] 1-5 6-10 ...-> [1..5] ++ [6..10]
My question is what it the best type in order to store this information ?
Is it necessary to preserve the structure of separate ranges or would it be ok to just store [Int] or Set Int?

Is it necessary to preserve the structure of separate ranges or would it be ok to just store [Int] or Set Int?
I think that it is efficient to keep the structure, but since haskell is lazy, I am wondering, if the best solution would not be to create the Set of Int. (An Ordered Set). the next step of the process, is for each index, to open a file corresponding to the index. In this file there is a bunch of images. At the end we have a Set associated to a number of images. This is the stream of images I have to treat. I split this into chunck and process each of them in parallel via a mapConcurrently. I do not know if this help... cheers Frederic

On Mon, 4 Oct 2021, PICCA Frederic-Emmanuel wrote:
Is it necessary to preserve the structure of separate ranges or would it be ok to just store [Int] or Set Int?
I think that it is efficient to keep the structure, but since haskell is lazy, I am wondering, if the best solution would not be to create the Set of Int. (An Ordered Set).
Set Int is not lazy. [Int] is lazy, but it is inefficient for eliminating duplicates. IntSet is also strict, but internally it is almost a bit vector, i.e. storage efficient. If the ranges are really large, then you might need data-interval&friends. However, a list of numbers of image files might not be that large, and IntSet will probably be a good choice.

Set Int is not lazy. [Int] is lazy, but it is inefficient for eliminating duplicates. IntSet is also strict, but internally it is almost a bit vector, i.e. storage efficient. If the ranges are really large, then you might need data-interval&friends. However, a list of numbers of image files might not be that large, and IntSet will probably be a good choice.
We have 100 files with 3000 images. 300000 * 4 bytes = 1.2 M is it that big ?

On Mon, 4 Oct 2021, PICCA Frederic-Emmanuel wrote:
Set Int is not lazy. [Int] is lazy, but it is inefficient for eliminating duplicates. IntSet is also strict, but internally it is almost a bit vector, i.e. storage efficient. If the ranges are really large, then you might need data-interval&friends. However, a list of numbers of image files might not be that large, and IntSet will probably be a good choice.
We have 100 files with 3000 images.
300000 * 4 bytes = 1.2 M
is it that big ?
I am afraid, I still do not understand where you need the list of Ranges. In the original post you said, you want to parse a list of ranges like the one for pages to print in a printer dialog. Is it to select files from the 100 ones or is it to select images from the 300,000 ones? In the first case I would use IntMap, in the latter case I would use Interval data structures.

I am afraid, I still do not understand where you need the list of Ranges. In the original post you said, you want to parse a list of ranges like the one for pages to print in a printer dialog. Is it to select files from the 100 ones or is it to select images from the 300,000 ones? In the first case I would use IntMap, in the latter case I would use Interval data structures.
Yes exactly these range are there to select an hundred files from a series of thousans :). then for each file I have the number of images. at the end I have a dedicated type called Chunk which allows to split the stream But you are right at this stage I do not need the initial range, since I already have the file name and the number of image Cheers data Chunk n a = Chunk !a !n !n deriving instance (Show n, Show a) => Show (Chunk n a) cweight :: Num n => Chunk n a -> n cweight (Chunk _ l h) = h - l csplit :: Num n => Chunk n a -> n -> (Chunk n a, Chunk n a) csplit (Chunk a l h) n = (Chunk a l (l + n), Chunk a (l+n) h) chunk :: (Num n, Ord n) => n -> [Chunk n a] -> [[Chunk n a]] chunk target = go target target where go :: (Num n, Ord n) => n -> n -> [Chunk n a] -> [[Chunk n a]] go _ _ [] = [] go tgt gap [x] = golast tgt gap x go tgt gap ~(x:xs) = let gap' = gap - cweight x in if | gap' > 0 -> cons1 x $ go tgt gap' xs | gap' == 0 -> [x] : go tgt tgt xs | (x1, x2) <- csplit x gap -> [x1] : go tgt tgt (x2 : xs) cons1 x cs = (x : Prelude.head cs) : tail cs golast tgt gap x = if | cweight x <= gap -> [[x]] | (x1, x2) <- csplit x gap -> [x1] : golast tgt tgt x2 {-# SPECIALIZE chunk :: Int -> [Chunk Int FilePath] -> [[Chunk Int FilePath]] #-}
participants (4)
-
Branimir Maksimovic
-
Henning Thielemann
-
Merijn Verstraaten
-
PICCA Frederic-Emmanuel