Why does the `Context` of a `Pattern` depend on whether I use mini-notation to define it?

I expected these two Patterns to be the same. (To evaluate this in GHCI one first needs to :set -XScopedTypeVariables -XOverloadedStrings.)

p1 :: Pattern String = "x"
p2 :: Pattern String = pure "x"

If I only inspect their Show instances, they do appear to be the same:

*Sound.Tidal.Context> p1
(0>1)|"x"
*Sound.Tidal.Context> p2
(0>1)|"x"

But if I query them, one has a nonempty Context while the other doesn't:

*Sound.Tidal.Context> s a b = State { arc = Arc a b, controls = mempty }
*Sound.Tidal.Context> query p1 (s 0 1)
[[((1,1),(2,1))](0>1)|"x"]
*Sound.Tidal.Context> query p2 (s 0 1)
[[             ](0>1)|"x"]

(I've inserted space above to make the two results easier to compare.)

What's going on?

Implementation of pure creates the empty context:

[ugh, I didn't mean this code to be inlined here]

For the other pattern, mininotation parser inserts source locations.

[EDIT] with pure, mininotation parser is not used at all.

I think the context is only used by feedforward/tidal-gui in the code highlighter to figure out which parts of the code to actually highlight (it's actually a list of pairs of coordinates in the editor), so I wouldn't really worry about it too much

Yes. Perhaps it's better to hide Context from this kind of output?

[EDIT] sorry I gave the wrong source code location for that.

1 Like

Yeah I agree that we should hide it by default, it's probably in there for testing purposes

To clarify (for myself, mostly ...) this is about instance Show (Event a).

Contexts are already hidden in instance Show (Pattern a).

The original poster used query(Arc) to show Events.

"t(1,8)":: Pattern Bool
(0>⅛)|True
...
queryArc ("t(1,8)":: Pattern Bool) (Arc 0 1)
[[((1,1),(2,1)),((3,1),(4,1)),((5,1),(6,1))](0>⅛)|True,...]

Aha! It doesn't matter when playing, in short, but I'll have to modify my tests to ignore those Contexts. Thanks all!

I agree, it seems reasonable to modify the Show instance of Event to not show the Contexts.

Opened a pull request:

1 Like

Ditto:

1 Like

Ah nice, didn't think of Eq or Ord.
And I think your implementation of the Ord instance without considering the contexts is ok

1 Like

PS Here's my latest PR to that effect. The earlier one had problems (and my attempts to update it went awry somehow).