[Haskell-cafe] Where is the hole?

Brandon Allbery allbery.b at gmail.com
Fri Aug 11 15:39:43 UTC 2017


On Fri, Aug 11, 2017 at 11:25 AM, Baa <aquagnu at gmail.com> wrote:

> I have code (this is the fragment only):
>
>   {-# LANGUAGE CPP                 #-}
>   ...
>   ...
>     let user' = ...
>     ...
>     else defect $ logger # ("authentication failure (user: " ++ user' ++
> ")") #: __LINE__
>     ...
>   ...
>
> and I get compilation error:
>
>         • Found hole: __LINE__ :: Int
>           Or perhaps ‘__LINE__’ is mis-spelled, or not in scope
>

You do understand that CPP refers to the C preprocessor, correct?

Or perhaps it is C syntax that you are unaware of.

Haskell does not get to tell a C preprocessor to follow Haskell rules
instead of C rules. In the referenced chunk, there are two things that can
cause problems: the single quote, which in the C preprocessor begins a
string-like entity (character literal.. for historical reasons, C (char)
literals can have multiple characters!), and the # which in mid-line
indicates a token pasting operation of some kind.

And in this particular case, the #s probably just got eaten, and the '
means the following __LINE__ was in what the C preprocessor thought was a
long (char) constant and therefore did not get expanded. Since it has a
leading underscore in its name, and is not known to be bound *at the
Haskell level*, it is interpreted as a hole.

If you are using LANGUAGE CPP, you must avoid Haskell syntax that is not
also valid C tokens. This is the downside of using a tool intended for a
different language with different syntax rules.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170811/737492c9/attachment.html>


More information about the Haskell-Cafe mailing list