dg
dg copied to clipboard
Use << and >> for functional composition
Idea: follow Elm's lead and use >>
and <<
for function composition.
-- Why? What's wrong with the current syntax?
Two things:
-
Inconsistency.
<-
is not the opposite of->
:-
->
means "this is a function" -
<-
means composition
There's no symmetry.
-
-
You can compose in only one direction (right to left).
-- But... if we did that, what would be the syntax for bit shifting?
Well, this is a matter for debate. I have a few suggestions:
-
>>>
and<<<
-
shift>
and<shift
Or we could follow Elm's steps again and simply not have them!
(Seriously: when was the last time you used bit shifting in a high-level language? I used to do it when I programmed in C. In 10 years of Java, I used it once. And never in JS or Python).
What about <<<
and >>>
? That's what I define composition as in my purescript prelude.
Also if <<
and >>
are already bit shifts probs best not to make a breaking change.
I picked up a bunch of nice stuff from elm, like composition and the <|
style for the traditional $
. But those ideas aren't from elm (that example is F# I think).
Re elm: 0.18 to 0.19 broke my respect for Elm. Removal of custom operators is a sign of the condescending nature of Elm, IMO, and doesn't help the language grow and develop.
Oh, and I use both shifts and composition, but my use case is atypical. Though never used bit shifts in dg.
What about <<< and >>>?
Well, it's better than the current situation, I guess. But, still: in a language like dg, composition is probably used way more than bit-shifting. I'd argue that the most used feature should have the shortest syntax (think ==
and =
in C; ::
and :
in Elm).
(...) probs best not to make a breaking change.
But wouldn't it be worth it?
Besides, breaking backwards compatibility -- that's what experimental / in development languages do. Look at how many times Elm did it. And Rust (pre-1.0).
How large is dg's user base? Of these users, how many use bit shifting? Is there a way to get some estimate on these numbers?
I'm guessing that (1) dg doesn't have a lot of users and (2) of those, (almost) nobody uses bit-shifting.
But those ideas aren't from elm (that example is F# I think)
Yes, |>
and <|
were "borrowed" from F#.
Seriously: when was the last time you used bit shifting in a high-level language?
Well, almost all of my pinned projects use bit shifts, I think? dg itself for what I guess you could call C FFI (constructing flags in CPython objects), dogeweb for websockets, webmcast for EBML... Recently I've been writing mainly Kotlin, and the bit shifts I had there were for JVM spec-defined structures. They're practically required when dealing with file formats and protocols, though I guess this is not really enough to give them dedicated special operators.
But, still: in a language like dg, composition is probably used way more than bit-shifting.
Is it? Unlike languages specifically designed for that, you need to use bind
for currying anyway, so maybe you're better off just writing pointful code...
Flow uses <.
and .>
.