Reference to blog post which advocated using `=:` (or was it `:=`?) as `(,)`?

I remember reading about that not long ago, now scoured the Haskell Weekly newsletter etc, but can’t find it anywhere…

From http://planet.haskell.org/ , is this what you are looking for: Oleg's gists - Infix operator for pair type and term

8 Likes

And it was in issue 376 of the Haskell Weekly newsletter :smiley:

4 Likes

Great idea to make the operator ‘bind very loosely’. And a Pattern Synonym spelled the same. (That’s going to get in trouble with the thought police.)

But lexeme :=? That’s ALGOL/Pascal assignment (destructive). I’d have used almost any other name.

Scala has a -> b at the term level, though I expect that’s a bit of a non-starter at home.

I just:

let (~) = (,)
    infix 0 ~ in

in a scope when I need it, taking care not to put it on the top level.

When I said

I should have said ‘… except ~’. Because (,) is both a type and a term constructor, so we can use punning. And the same applies for Oleg’s :=. But ~ is already a type constructor/operator for type unification (constraint). (It’s not actually a reservedsym, but is for practical purposes.) So we get

(~) :: a -> b -> (a, b)   -- no: not unifying a, b 

Well exactly. So you have to pepper local let throughout your code, rather than putting one decl in one place and importing it everywhere. Both confusing and dysergonomic. (Also rather liable to give parse errors, because in patterns ~ means lazy match. Oh, but although (,) is a constructor so can appear in patterns, operator ~ isn’t so can’t. Then the parse errors would be only in the readers’ heads.)

1 Like

Except ! (strictness annotation) is already being abused by Data.Vector.

My pov is, if you’re going to use a weird synonym for (,), it’s better to set it locally scoped, at least until the community decides on a standard synonym for (,) and pushes it into base.

~ works well enough for me, the use case is for maps when you need a more convenient way to type it out other than (foo,bar) per entry.

1 Like

Thanks!

I stumbled upon this GHC issue #8967: Add syntax for creating finite maps and sets · Issues · Glasgow Haskell Compiler / GHC · GitLab and wanted to add a comment to that :slight_smile:

1 Like

It was also proposed more recently in GHC issue #20110: Add pair operator to base.