Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPPHS fails to substitute constant #25

Open
LeventErkok opened this issue Mar 7, 2021 · 0 comments
Open

CPPHS fails to substitute constant #25

LeventErkok opened this issue Mar 7, 2021 · 0 comments

Comments

@LeventErkok
Copy link

This program:

{-# LANGUAGE CPP                  #-}
{-# LANGUAGE DataKinds            #-}
{-# LANGUAGE KindSignatures       #-}
{-# LANGUAGE TypeOperators        #-}
{-# LANGUAGE TypeFamilies         #-}
{-# LANGUAGE UndecidableInstances #-}

import Data.Kind
import Data.Type.Equality
import GHC.TypeLits

#define N 2

type family V (e :: Nat) :: Constraint where
  V (e :: Nat) = (e `CmpNat` N ~ 'EQ, e `CmpNat` N ~ 'LT)

fails to generate a correctly expanded output, thus causing compilation failure down the line.

The relevant part of the expanded output is:

type family V (e :: Nat) :: Constraint where
  V (e :: Nat) = (e `CmpNat` 2 ~ 'EQ, e `CmpNat` N ~ 'LT)

Notice that CPPHS substituted for the first occurrence of N, but not the second. Most likely it's getting confused by the occurrence of two ' characters, and leaving whatever is inside untouched. But that's not a valid Haskell character, so I would've expected this to work correctly.

There's a simple work-around by putting the second part in a line by itself:

  V (e :: Nat) = ( e `CmpNat` N ~ 'EQ
                 , e `CmpNat` N ~ 'LT)

in which case the expansion correctly replaces N in both lines.

So, there's a work around; but would be nice if it wasn't needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant