> If the answer is no, is there any interest in including these three
> functions (as well as compose-5, 6, 7, 8) into Typed Racket?
I think these would be excellent in a package.
Someday later, perhaps poly dots and #:rest-star can combine to
improve the built-in type.
On Wed, Dec 09, 2020 at 10:16:16PM -0800, unlimitedscolobb wrote:
> I'm not sure whether macros could be of use here. I'll give it a think.
Idea: Have a look at parendown https://docs.racket-lang.org/parendown/index.html
It would let you write
(compose f
(compose g
(compose h k)))
as
( compose f
#/ compose g
#/ compose h k
)
Which at least cuts down on the heavy indentation and parenthesis pile-up.
A macro might be able to generate either of the above from
(comp f g h k)
.
>> A package for compose-n and compose-3 to like 10 or 20?
Yes
I like the idea of _small packages that do one thing_ better than
_one-stop all-utility packages_ ... but do what you think makes sense.
>> Someday later, perhaps poly dots and #:rest-star can combine to
>> improve the built-in type.
>>
>
> From my naive viewpoint, I don't really see other natural ways of improving
> the type of compose other than what I wrote, the problem being that writing
> the type for arbitrary-arity composition would require specifying equality
> between the return type of every function and the argument type of the
> preceding one. I'm not sure even Coq and Agda have that facility directly,
> certainly not Haskell or Idris to the best of my knowledge. I don't expect
> them to go beyond binary compose, because it's sufficient to do any
> compositions. It's that in Racket I find writing chains of nested compose
> calls somewhat clunky.
Typed Racket already has some domain-specific ideas to support the
#:rest-star option. The equality-chaining constraint is definitely
new, but doesn't seem out of the question.
https://github.com/racket/typed-racket/blob/master/typed-racket-lib/typed-racket/rep/type-rep.rkt#L586-L612
I think other languages (Coq Agda Haskell Idris) have a harder time
here because they want to support currying. And even if they added
#:rest-star logic, their users might call it an anti-pattern because
it doesn't fit with partial application.
syntax-parse
can already perform pattern matching. No need to use match
(define-syntax (multi-compose stx)
(syntax-parse stx
[(_ f:expr g:expr)
#'(compose f g)]
[(_ f:expr funcs:expr ...)
#'(compose f (multi-compose funcs ...))]))
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/219c189f-dd93-4b18-9ef9-2ff477ce3a15n%40googlegroups.com.