I've been wondering if having an 'alignment' datatype would help.. So to combine two patterns, first you align them, then you combine the elements that align.
squeeze2 "1 2 3" "4 5" :: Alignment (Signal Int)
If somehow Alignment (Pattern a)
could itself be an instance of Pattern a
, then hopefully with some plumbing the above could be treated as Signal Int
, by automatically turning itself into a stack
post-alignment, i.e. "[1,[4 5]] [2, [4 5]] [3, [4 5]]
.
The 2 in squeeze2
means squeeze two things together. It could have an infix operator alias, like "1 2 3" << "4 5"
or whatever. squeeze
could work on a list instead, e.g. squeeze ["1 2 3", "4 5", "6 ~ 7"]
But you could also combine the aligned patterns like
combine (+) (squeeze2 "1 2 3" "4 5")
With common aliases like add = combine (+)
.
Again with some clever use of classes something like add
might also be able to support some default, implicit alignment (like the current 'overlay and take structure from the left' behaviour) to allow add ["1 2 3", "4 5"]
, add2 "1 2 3" "4 5"
, "1 2 3" + "4 5"
, etc.
But beyond that default behaviour, for simplicity it could be nice to avoid the combinational explosion of operators that both align and combine elements.
So far I've talked about signals but what about sequences? It would make a lot of sense to be able to squeeze a sequence into a signal, for example. It's not really possible to squeeze a signal into a sequence, because a signal is infinite but a sequence is finite. But you could squeeze the first cycle of a signal into a sequence, if you wanted. Some more type class cleverness could make this possible.
Taking an example from above, a puzzle is what to do where we are composing operations on patterns rather than just the elements, like with this example from above:
fastSqueeze "2 3 3" “bd sd”` giving the equivalent of `"[bd sd]*2 [bd sd]*3 [bd sd]*3"
So with alignment as a separate step I guess we'd want to be able to do fast $ squeeze2 "2 3 3" "bd sd"
.. but then squeeze2 "2 3 3" "bd sd"
is an alignment of different types. That might be a bit difficult to represent..