[Haskell-cafe] Some thoughts on Type-Directed Name Resolution

AntC anthony_clayden at clear.net.nz
Tue Jan 31 11:27:25 CET 2012

Donn Cave <donn <at> avvanta.com> writes:

> On 28/01/2012 13:00, Paul R wrote:
> ...
> > All this dot syntax magic frankly frightens me. Haskell, as a pure
> > functionnal language, requires (and allows !) a programming style that
> > just does not mix well with object oriented practices. 
> In the glasgow-haskell-users discussion, it has been pointed out (to 
> little apparent effect) that the current notation for access by field
> name, `field record', is naturally functional and is easier to read
> for a functionally trained eye than a postfix `record.field' alternative.
> [snip]
> 	Donn
Donn, I can see the argument "Haskell has never been afraid to be different. 
Just because OO does it like that, so what?"

But if you read SPJ's discussion in the TDNR proposal, there's "a cultural 
connection to OO". My post at the head of this thread put it as "focus on the 
object -> look for the action".

Of course it's easy to 'fake' postfix function application:
    (.$) = flip ($)

But the trouble is that .$ binds weakly. What we want is for the dot to bind 
tighter even than function apply. So:
     crack egg.largeEnd   ==> crack (largeEnd egg)
(Where ==> means 'is syntactic sugar for'.)

We're already familiar with the tight-binding dot for qualified names. I 
suppose we're coping with the visual confusion with space-surrounded dot as 
function composition.

But I can see that "one more petit bonbon" could tip confusion over the edge.

To my eye, one-sided dot application is a bonbon too far.

My proposal is that field selection functions be just ordinary functions, and 
dot notation be just function application(tight-binding). Then:
      object.fieldfuncmethod   ==> fieldfuncmethod object
(Subject to the tight binding for the dot.)
And one-sided dot application is pointless (! errk I mean 'without purpose', 
no different to writing the bare object or bare fieldfuncmethod).

Then you can write in your familiar style, and can use polymorphic field 
selectors as plain functions (same syntax as presently).

Those under the influence of OO can write dot notation, until they discover 
the joys of pointless style.


More information about the Haskell-Cafe mailing list