tidalcycles / Tidal

Pattern language
http://tidalcycles.org/
GNU General Public License v3.0
2.26k stars 256 forks source link

Feature requests for tidal-parse #577

Closed yaxu closed 2 years ago

yaxu commented 4 years ago

An issue for collecting requests for missing functions, operators and syntax for tidal-parse (formerly known as minitidal)

yaxu commented 4 years ago

Functions:

Desirable syntax:

Potentially useful syntax:

yaxu commented 4 years ago

This doesn't work, but only because id is missing from tidal-parse:

spread ($) [id, rev, fast 2]

I could add it to genericTransformations, but that isn't generic enough, as id is a -> a, not Pattern a -> Pattern a. So @dktr0 the question is, how low do we want to go?

dktr0 commented 4 years ago

I would just add it to genericTransformations for now, since I don't think there are currently any other places (in tidal-parse) where a -> a would be used. And later rework.

yaxu commented 4 years ago

@dktr0 Ok, I suppose there are not many non-patterned parameters left, so a -> a is pretty much out of scope anyway

yaxu commented 4 years ago

One liner to get a list of functions currently supported by tidal-parse:

perl -e 'undef $/; $all = <>; while ($all =~ /fromTidal\s*"([^"]+)"/og) {print "$1\n"}' Parse.hs |sort > current.txt

Hacky one liner to get a list of functions in a module with type:

echo ":browse Sound.Tidal.UI" | ghci |perl -e 'undef $/; $_ = <>; s/^GHC.*?\n//g; s/Prelude> //g; s/\n +/ /go; s/(?:\n|^)(\()Sound\.Tidal\.\w+?\./\n$1/sg; s/\nLeaving.*//; s/^\n//; print'|egrep -v '^_' > ui.txt

Another hack to make a list of missing functions:

perl -e '@ui = `cat ui.txt`; chomp @ui; @current = `cat current.txt`; chomp @current; foreach $type (@ui) {$type =~ s/Sound\.Tidal\.\w+\.//g; $type =~ /^(\S+) (.*)/; $func = $1; $type = $2; if (not (grep {$func eq $_} @current)) {print "- [ ] **$func** `$type`\n"}}'
yaxu commented 4 years ago

Here's a version of the above (now deleted) lists combined, with most internal functions removed, and sorted by type, not name

Made with

perl -e '@foo = `cat list.txt`; chomp @foo; @bar = map {$_ =~ /(::.*)/; [$_,$1]} @foo; @qux = sort {$a->[1] cmp $b->[1] || $a->[0] cmp $b->[0]} @bar; @final = map {$_->[0]} @qux; foreach $line (@qux) {print "$line->[0]\n"}'
dktr0 commented 4 years ago

Well that's post-modern (using Perl to analyze Haskell projects)!

dktr0 commented 4 years ago

Not to be nitpicky but it does seem to identify some things as missing that are not missing, especially operators like |/|

yaxu commented 4 years ago

It's entirely possible that my crufty regex approach wasn't 100% accurate!

dktr0 commented 4 years ago

Might just be something to do with difference between <| and (<|)?

yaxu commented 4 years ago

Yes probably, I've ticked them off for now

dktr0 commented 4 years ago

Now I understand what the tick boxes are for! :)

dktr0 commented 4 years ago

This is all super useful - will be easy to fill all this in in the next little while

yaxu commented 4 years ago

Good! Out of interest, are you able to tick the boxes by clicking on them in my comment?

dktr0 commented 4 years ago

I just checked the last one spuriously - is it checked for you? I guess I kind of doubt it...

dktr0 commented 4 years ago

(juxcut')

yaxu commented 4 years ago

Yes that worked, I unchecked it again

yaxu commented 4 years ago

I've been doing a couple more of these (pr soon), but can you summarise the reason for not generating all this straight from the types @dktr0 ? Is there some pragmatism about how the currying works?

dktr0 commented 4 years ago

Just haven't got that far with the TH and prefer something that works right now and which gives workshop experiences with Tidal to hundreds of students at a time over abstraction and automation for the sake of abstraction and automation...

dktr0 commented 4 years ago

I know I can debug and maintain this. I do not know that for the fully automatic one.

dktr0 commented 4 years ago

Still, I think the automatic thing will probably be the right step eventually...

dktr0 commented 4 years ago

Basically I think that's a big and complicated refactor, with uncertain ultimate costs, and not a huge payoff in terms of what it makes available to the audiences I care about. If someone else is able to pull it off, great I guess (although I worry a bit about not being able to follow/debug it from that point on...).

yaxu commented 4 years ago

I meant auto-generating the code (e.g. using more shonky perl code) rather than doing funky stuff with TH.

yaxu commented 4 years ago

If it's doable, I'd be happy to do the job! Just need to understand what's going on and what the gotchas are..

yaxu commented 4 years ago

Having problems working out how to add the Ord constraint in rot :: Ord a => Pattern Int -> Pattern a -> Pattern a

In this case I think I can just remove that constraint from the function itself though..

yaxu commented 4 years ago

Hm I can only get it to rot :: Eq a => Pattern Int -> Pattern a -> Pattern a, as some comparison of values has to happen.

dktr0 commented 4 years ago

These kind of questions are part of why I am reluctant to automate further than already - it sounds nice but there are lots of little wrinkles that IMHO are easier to think through at a lower level of abstraction. Obviously your mileage may vary. Not super in favour of doing things in Perl as it will further limit my ability to continue contributing to this work (I don't have time and energy to spend on Perl, sorry).

dktr0 commented 4 years ago

I'll add rot now and add it to the pull request already in the queue for clip and vol.

dktr0 commented 4 years ago

I do think the higher abstraction TH route is viable - just takes some careful thought and very careful documentation...

dktr0 commented 4 years ago

Ok rot is there in the pull request with vol and clip now.

dktr0 commented 4 years ago

also added the fastCat/slowCat synonyms

dktr0 commented 4 years ago

Basically adding something like rot that has a type (ie. with the constraints) we don't already have is about adding a new instance or definition for that type, then taking off the first argument and repeating the process (adding new instances or definitions as appropriate) until you get to the * instances, where you make sure the new pathway is reflected in every one of them that is possible.

dktr0 commented 4 years ago

Can I propose that we start conceptual work that lays the groundwork for the more-abstract-TH route without (yet) doing away with the current approach? It will be more robust and hopefully we will both be able to follow and continue to contribute to the result.

yaxu commented 4 years ago

Thanks for the rot! I don't intend to make Perl a dev dependency for anything.. Just trying to work out whether we can just generate these definitions as a one-off. It seems that we're just describing a type in code, which seems to be a data munging rather than manual task.. But I think I'm missing something, and so was asking what that missing thing was.

dktr0 commented 4 years ago

I've gotten as far as making some TH to take a list of Tidal functions and get the info about their type as a Map from their names to that info. Here's it in action:

*Sound.Tidal.Parse> $(reifyTidals ["s","n"] >>= (stringE . show)) "fromList [(\"n\",VarI Sound.Tidal.Params.n (AppT (AppT ArrowT (AppT (ConT Sound.Tidal.Pattern.Pattern) (ConT GHC.Types.Double))) (ConT Sound.Tidal.Pattern.ControlPattern)) Nothing),(\"s\",VarI Sound.Tidal.Params.s (AppT (AppT ArrowT (AppT (ConT Sound.Tidal.Pattern.Pattern) (ConT GHC.Base.String))) (ConT Sound.Tidal.Pattern.ControlPattern)) Nothing)]"

dktr0 commented 4 years ago

Have pushed that to a branch called th-parse on my fork for now

yaxu commented 2 years ago

Is this issue still useful @dktr0 ?

dktr0 commented 2 years ago

@yaxu Nah, not really, I'll close it!