flxw 2017-02-26 07:26:43
Hello all. I've got a list of interesting things, interspersed with uninteresting stuff. And two predicates for testing where an "interesting" interval starts and ends.
flxw 2017-02-26 07:26:43
Let's say the list type is [Int], and even and odd are the predicates. I use span and explicit recursion to get from e.g. [1,2,4,3,6] to [[2,4], [6]].
flxw 2017-02-26 07:26:43
My question: Right now the list is small, so I don't mind going over it two or three times with diffeerent pairs of predicates (to find intervals accordingto different criteria).
flxw 2017-02-26 07:26:43
But how could an approach look like where I'd need only a single run over the list, whilst testing for various interval bounds in parallel? I could imagine brute forcing it using State, but would there be a more functional approach, too? ;)
lyxia 2017-02-26 07:29:22
flxw: http://hackage.haskell.org/package/foldl might be of interest
benzrf 2017-02-26 07:31:49
flxw: ooh, that's an interesting problem :)
pavonia 2017-02-26 07:31:54
There also is a function to partition a list according to a specified predicate, but I can't recall the name
pavonia 2017-02-26 07:35:33
@hoogle Ord b => (a -> b) -> [a] -> [[a]]
lambdabot 2017-02-26 07:35:33
GHC.Exts groupWith :: Ord b => (a -> b) -> [a] -> [[a]]
lambdabot 2017-02-26 07:35:33
Data.List.Extra groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]]
lambdabot 2017-02-26 07:35:33
Extra groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]]
benzrf 2017-02-26 07:35:33
flxw: actually, im not sure you'd save much time that way
benzrf 2017-02-26 07:35:33
flxw: my first thought would be that the complexity of going thru the list once, doing each predicate per item, is "listLength * numPreds" - and doing each predicate, going thru the list for each, is "numPreds * listLength"
benzrf 2017-02-26 07:35:33
am i wrong?
flxw 2017-02-26 07:35:33
lyxia: This looks interesting. Thank you. It'll take me a bit to understand how to use it, but I can see already that it will be a great investment generally.
Rub_ixCube 2017-02-26 07:38:14
umm, I followed the instructions but the installation isn't global...
Tuplanolla 2017-02-26 07:38:18
If I want a single error handler for two threads, does using an extra waiting thread just for that seem wasteful?
Rub_ixCube 2017-02-26 07:44:59
oh
Rub_ixCube 2017-02-26 07:45:02
:P
flxw 2017-02-26 07:46:36
it is system-ghc: true
flxw 2017-02-26 07:46:49
this is how I make stack use ghc's HEAD sometimes.