Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code example in API comment for spread' is broken #1108

Open
jwaldmann opened this issue Jan 19, 2025 · 2 comments
Open

code example in API comment for spread' is broken #1108

jwaldmann opened this issue Jan 19, 2025 · 2 comments

Comments

@jwaldmann
Copy link
Contributor

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)

@bgold-cosmos
Copy link
Contributor

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.

@yaxu
Copy link
Member

yaxu commented Jan 20, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants