[Haskell-cafe] Re: Fractional/negative fixity?

Dan Weston westondan at imageworks.com
Tue Nov 7 19:20:52 EST 2006


I started this e-mail thread on HaskellCafe instead of HaskellPrime 
because it was minimal, backwards-compatible, valid Haskell 98 (or very 
nearly so) and could go (now) into GHC if someone saw fit to put it in.

 > If you think C++ is not overly complicated, just what is a protected
 > abstract virtual base pure virtual private destructor, and when was
 > the last time you needed one?
 >    -- Tom Cargil, C++ Journal

The above was not a proposal for Haskell'.

 > Proposers of new [C++] features should be required to donate a 
kidney.  > That would - Jim [Waldo] pointed out - make people think hard 
before
 > proposing, and even people without any sense would propose at most two
 > extensions.
 >     -- Bjarne Stroustrup, creator of C++

But at the risk of losing a kidney...

Here's where I think Haskell 98 got it wrong:

"A fixity declaration may appear anywhere that a type signature appears 
and, like a type signature, declares a property of a particular operator."

Like a type signature? A type signature has semantic value, fixity does 
not. In principle, neither does the name that a lambda abstraction is 
bound to in top-level definitions, but we are stuck with linkers that 
know about names. They don't know about fixity.

Operator precedence is a purely syntactic device for people (like me) 
who hate parentheses. Its "scope" is essentially local to the attention 
span of a human being (i.e. a single module). A preprocessor can 
parethesize code to eliminate the need for fixity. I hate chasing other 
modules looking up operator fixity and would rather just specify it myself:

What if we could remap fixity on import:

-- (MyModule.???) fixity is 4, exported as its default...
import MyModule((???))

-- But in this module I prefer 5...
-- This fixity is *not* exported!
infix 5 ???

Modules that import this module get the default fixity from the source.

Summary: fixity at definition is exported, fixity on import is locally 
remapped but not reexported.

 > Better is the enemy of the good
 >    -- Voltaire

Simple, powerful, minimal. Any takers?

Dan

Dan Weston wrote:
> Here's an idea that (I think) is useful and backwards compatible: 
> fractional and negative fixity.
> 
> There have been 3 separate times where I've wanted an operator just 
> above 0 ($) but less than 1 (>>= or >>>), or else just below 0 (like a 
> superlow $$)
> 
> infix  0.5 ???
> infix -1   $$
> 
> The only change would be internal to compiler, wouldn't it? Since fixity 
> is just syntactic sugar, there should be no semantic difficulties.
> 
> Dan
> 




More information about the Haskell-Cafe mailing list