Tidal icon indicating copy to clipboard operation
Tidal copied to clipboard

code example in API comment for spread' is broken

Open jwaldmann opened this issue 11 months ago • 3 comments

https://hackage.haskell.org/package/tidal-1.9.5/docs/Sound-Tidal-UI.html#v:spread-39-

GHCi, version 9.10.1: https://www.haskell.org/ghc/  :? for help
ghci> import Sound.Tidal.Context 
ghci> :set -XOverloadedStrings 
ghci> :t spread' slow "2 4%3" $ sound "ho ho:2 ho:3 hc"
<interactive>:1:14: error: [GHC-39999]
    • No instance for ‘Enumerable (Pattern Time)’
        arising from the literal ‘"2 4%3"’
    • In the second argument of ‘spread'’, namely ‘"2 4%3"’
      In the first argument of ‘($)’, namely ‘spread' slow "2 4%3"’
      In the expression: spread' slow "2 4%3" $ sound "ho ho:2 ho:3 hc"

this version is type-correct (inserting pure)

spread' slow (pure "2 4%3") $ sound "ho ho:2 ho:3 hc"

is that how it's supposed to be used? (I guess not, since implementation then does pure "..." >>= _ where the monadic-bind is useless)

then perhaps this?

spread' slow (fmap pure "2 4%3") $ sound "ho ho:2 ho:3 hc"

NB: to catch documentation bugs like this, it would be good to have a method of evaluating examples (like https://github.com/sol/doctest#readme) (at least, type-checking)

jwaldmann avatar Jan 19 '25 13:01 jwaldmann

It looks like the docs are out of date there. spread' is meant to be used with functions that don't take "patternified" arguments. So

spread' _slow "2 4%3" $ sound "ho ho ho hc"

evaluates correctly. But a lot of Tidal functions were updated so that their "vanilla" version already accepts pattern arguments, which makes spread' mostly redundant in those cases.

bgold-cosmos avatar Jan 19 '25 14:01 bgold-cosmos

Yes when spread' was written, the signature of slow would be

slow :: Time -> Pattern a -> Pattern a

now of course it's

slow :: Pattern Time -> Pattern a -> Pattern a

and patterns of numbers are numbers so slow 2 still works. The unpatternified function _slow exists but only for internal use to try to be a bit more efficient in cases where the value is never a pattern.

As you say spread' is now redundant. I think we should probably just remove it.

yaxu avatar Jan 20 '25 13:01 yaxu

spread' is still used to pattern rotL in e.g. randcat and index.

  1. what does this mean for spread'?
  2. in case of it's redundancy, should we only remove spread' or spread-everything?

sss-create avatar Feb 13 '25 21:02 sss-create