monadfix / named

Named parameters (keyword arguments) for Haskell
Other
91 stars 5 forks source link

Consider having fancy type operator as an alias for 'Named' #5

Closed chshersh closed 6 years ago

chshersh commented 6 years ago

Like :=. For example, instead of this:

replace ::
  Text `Named` "needle" ->
  Text `Named` "replacement" ->
  Text `Named` "haystack" ->
  Text

users can write

replace ::
  "needle"      := Text ->
  "replacement" := Text ->
  "haystack"    := Text ->
  Text
int-index commented 6 years ago

Why?

chshersh commented 6 years ago
  1. Shorter.
  2. Cooler.
  3. Fancier.
  4. Looks more similar to function signatures of imperative languages, like this:
fun replace(needle: String, replacement: String, haystack: String) { .. }
int-index commented 6 years ago

Shorter.

Does being shorter justify introducing even more obscure syntax? Named is immediately understandable, := is not.

Cooler.

This is subjective.

Fancier.

And that's hardly an advantage.

Looks more similar to function signatures of imperative languages, like this:

Now that is a good point, but := looks like variable assignment! Had I the opportunity to use : without =, I'd definitely do that.

int-index commented 6 years ago

I guess "shorter" is a strong point since the library is meant to be used pervasively, but I'm not sold on :=. Maybe some other character sequence would do.

chshersh commented 6 years ago

but := looks like variable assignment!

That's a fair point! I can propose other alternatives:

::: =: :- -: :=: :-: :> :# :@

Had I the opportunity to use : without =, I'd definitely do that.

Could you overload : operator like you did with / and * in o-clock?

chshersh commented 6 years ago

Oh, also looks like := (and a lot of many others) are not even impossible to use...

int-index commented 6 years ago

I decided that I don't like any of those options.

neongreen commented 6 years ago

We could use Text : "foo" if we had -XOverloadedStringsDataKinds :trollface:

neongreen commented 6 years ago

no, nevermind, [*] is uninhabited

int-index commented 6 years ago

I'd like to be able to write "foo" : Text. This would be achievable with the following definition of : (approximately):

type family ColonK k1 k2
type instance ColonK a [a] = [a]
type instance ColonK Symbol Type = Type

type family (a :: k1) : (b :: k2) :: ColonK k1 k2
type instance name : ty = Named ty name
type instance x : xs = x ': xs

Unfortunately, : is built-in syntax and can't be used as a regular operator with TypeOperators.

chshersh commented 6 years ago

-XOverloadedDataKindsColonOperator anyone?..

chshersh commented 6 years ago

Authors of gdp paper use the following operator for their Named:

https://github.com/matt-noonan/gdp/blob/6f5abb6bfed90d17833bbd95490d7195e1fea72e/src/Theory/Named.hs#L41

I'm not sure, what is better: use the same operator so people can be familiar with concept through multiple sources (and no collisions) or use different operator to show that this is actually is different name.

P.S. I'm still hoping that -XOverloadedDataKindsColonOperator will be implemented some day... Probably with better name.