API Annotatons in a FunBind

Simon Peyton Jones simonpj at microsoft.com
Tue Dec 23 11:59:45 UTC 2014


If you do this

·         Please make Match into a record (it ought to be already)

·         Put a Note on the fun_id field, with an example like the one you give

I’m not really sure if Haskell lets you mix infix and prefix notation for the same function definition, as you have done.  The Report is silent on this question. I’m inclined to think “no”.

Currently a FunBind has a fun_infix field saying whether the definition uses infix notation.  That is fine if “no” above.

If all are prefix or infix, do you still need the new field in Match?  Would it matter only for operators where you want to know where to put the parens?  Even in normal code, how are you distinguishing (+ ) from ( +) or whatever?

Simon

From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of Alan & Kim Zimmerman
Sent: 15 December 2014 21:16
To: ghc-devs at haskell.org
Subject: API Annotatons in a FunBind

After individual FunBinds have been parsed, they are combined in getMonoBind.
In the process, all the original FunBind fun_id's bar one are discarded, including its location.
This causes a problem for source-to-source conversions of functions such as the following

(&&&  ) [] [] =  []
xs    &&&   [] =  xs
(  &&&  ) [] ys =  ys
Where there are compound RdrNames, and each has different spacing.
I am proposing to add a (Maybe (Located id)) to the Match datatype to deal with this.


data Match id body
  = Match
        Maybe (Located id) -- fun_id in subsequent function equations
        [LPat id]               -- The patterns
        (Maybe (LHsType id))    -- A type signature for the result of the match
                                -- Nothing after typechecking
        (GRHSs id body)
Is this a problem?
Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20141223/d2bbf9d7/attachment.html>


More information about the ghc-devs mailing list