3 ms·
Pretty nice. I hope future versions will allow some sort of embedded structures, eg for this segments let p1 = scat [c..c']^/4 p2 = delay (1/4) $
by anigbrowl 12y ago
Pretty nice. I hope future versions will allow some sort of embedded structures, eg for this segments
let
p1 = scat [c..c']^/4
p2 = delay (1/4) $ scat [c..c']^/4
p3 = delay (3/4) $ scat [c..c']^/4
in (accent . legato) (p1 </> p2 </> p3)
I would have expected something like
p2 = delay (1/4) $$ [p1]
or somesuch (sorry about the notation, I've never used Haskell - my point is about the nesting).
I would also love to see ways to define particular scales and modes and then specify operations within that scale space without necessarily articulating the individual notes. Of course at that point you're getting into compositional tooling rather than transcription.
Anyway, nice work and great documentation so far. Also good that there's a whole bunch of converters.
- nimish 12y agoYes there is nothing stopping you from doing let p1 = scat [c..c']^/4 p2 = delay (1/4) p1 p3 = delay (3/4) p1 in (accent . legato) (p1 </> p2 </> p3) It's a full programming language so you can do a lot more than that!
- roryokane 12y agoI don’t know much about Haskell, but I looked up `let`’s documentation, and I think it already does support embedded structures like you ask for. You can just write `p2 = delay (1/4) $ p1` (and you can also leave out the `$` because `p1` is already atomic). I think the site’s example repeats the definition of `p1` just to make reading the example clearer, not because you are forced to code like that.
- cstrahan 12y agoSome extra background on `$`, for the curious: Function application in Haskell is expressed like so: > f x Where `f` is a function, and `x` is it's argument. Function application is left associative, so > f x y Is equivalent to > (f x) y In this case, `(f x)` yields a new function, to which `y` is then applied (see http://en.wikipedia.org/wiki/Currying http://en.wikipedia.org/wiki/Currying). The function `$` that you mention is just application: > f $ x = f x So, using `$` infix like so > f $ x Is equivalent to > f x And likewise > delay (1/4) $ p1 is equivalent to > (delay (1/4)) p1 with extra parenthesis to make associativity clear. This begs the question: when is `$` ever a useful function? There are two cases that come to mind: 1) Precedence. `$` has the lowest precedence of any function, and can thus be used to omit otherwise necessary parens; this > f (g x) is equivalent to > f $ g x 2) Use in higher order functions. Imagine you have a function `all` that takes a predicate function `f` and a list of values `xs` and returns `True` if `f x` returns `True` for all `x` in `xs`. So `all (> 3) [4,5,6]` returns `True`. But, imagine now that you have a list of predicates and one value: can you still make use of `all` in this case? Yes, you could do something like this: > all (\f -> f 42) [even, (> 3), (< 100)] But that's a little verbose. If we look at `(\f -> f 42)`, all it's doing is taking a function and immediately applying `42` to it - hey, that sounds like `$` if it was partially applied to `42`! Here's a simpler version of the previous expression: > all ($ 42) [even, (> 3), (< 100)] So that's pretty much all there is to `$` and why one may omit it in the original expression.
- nbouscal 12y agoIf you really want to be concise, something like this should work. accent . legato $ foldl1 (</>) (delay <$> [0, 1/4, 3/4] <*> [scat [c..c']^/4])