Where is the hole?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Baa
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Where is the hole?

Baa
Hello, Dear List!

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
        • In the second argument of ‘(#:)’, namely ‘__LINE__’
          In the second argument of ‘($)’, namely
            ‘logger # ("authentication failure (user: " ++ user' ++ ")")
             #: __LINE__’
          In the expression:
            defect
            $ logger # ("authentication failure (user: " ++ user' ++ ")")
              #: __LINE__
        • Relevant bindings include...
        ... etc ...

But if I change variable name to `userx` (from user'), all is compiled
succesflully, no any holes. Where is the hole?

---
Best regards, Paul
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Where is the hole?

Joachim Breitner-2
Hi,

cpp easily gets confused by single primes in variables names, which do
not exist in C. You can use a better suited cpp implementation, such as
http://projects.haskell.org/cpphs/

Greetings,
Joachim

Am Freitag, den 11.08.2017, 18:25 +0300 schrieb Baa:

> Hello, Dear List!
>
> 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
>         • In the second argument of ‘(#:)’, namely ‘__LINE__’
>           In the second argument of ‘($)’, namely
>             ‘logger # ("authentication failure (user: " ++ user' ++
> ")")
>              #: __LINE__’
>           In the expression:
>             defect
>             $ logger # ("authentication failure (user: " ++ user' ++
> ")")
>               #: __LINE__
>         • Relevant bindings include...
>         ... etc ...
>
> But if I change variable name to `userx` (from user'), all is
> compiled
> succesflully, no any holes. Where is the hole?
>
> ---
> Best regards, Paul
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
--
Joachim “nomeata” Breitner
  [hidden email]
  https://www.joachim-breitner.de/

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Where is the hole?

Brandon Allbery
In reply to this post by Baa
On Fri, Aug 11, 2017 at 11:25 AM, Baa <[hidden email]> 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
[hidden email]                                  [hidden email]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Loading...