Nothing Special   »   [go: up one dir, main page]

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

Haskell --cnf backend produces code with error: Illegal type synonym family application #216

Closed
andreasabel opened this issue Nov 27, 2017 · 10 comments

Comments

@andreasabel
Copy link
Member

With ghc-7.10, the code generated by the Haskell CNF backend does not compile:

$ bnfc --haskell --cnf -m Calc.cf 
...
$ make

yields

Compiling CnfTablesCalc    ( CnfTablesCalc.hs, CnfTablesCalc.o )

CnfTablesCalc.hs:14:10:
    Illegal type synonym family application in instance:
      [(CATEGORY, Any)]
    In the instance declaration for ‘RingP [(CATEGORY, Any)]’
@jyp
Copy link
Contributor
jyp commented Nov 27, 2017

Could you show some of the context in CnfTablesCalc? Maybe it's a matter of using the right GHC extension.

@andreasabel
Copy link
Member Author

Here is some context (not the whole file):

{-# LANGUAGE MagicHash, FlexibleInstances #-}
module CnfTablesCalc where
import GHC.Prim
import Control.Applicative hiding (Const)
import Algebra.RingUtils
import Parsing.Chart ()
import AbsCalc
import LexCalc
import PrintCalc
readInteger :: String -> Integer
readInteger = read
readDouble :: String -> Double
readDouble = read
instance RingP [(CATEGORY,Any)] where
  mul p a b = trav [map (app tx ty) l :/: map (app tx ty) r | (x,tx) <- a, (y,ty) <- b, let l:/:r = combine p x y]
    where trav :: [Pair [a]] -> Pair [a]
          trav [] = pure []
          trav (x:xs) = (++) <$> x <*> trav xs
          app tx ty (z,f)  = (z, f tx ty)
showAst (cat,ast) = case cat of 
      CAT_Exp -> printTree ((unsafeCoerce# ast)::Exp)
      _ -> "Unprintable category"
data CATEGORY = CAT_Exp|
                CAT_0|
                CAT_1|
                CAT_Exp1|
                CAT_2|
                CAT_3|
                CAT_Exp2|
                CAT_4|
                CAT_Integer|
                TOK_40|
                TOK_41|
                TOK_42|
                TOK_43|
                TOK_45|
                TOK_47
  deriving (Eq,Ord,Show)

@jyp
Copy link
Contributor
jyp commented Nov 28, 2017

Looks the Any type has become a type family, so the above does not work any more. I suppose that it could be wrapped into another type, like

data OldAny = OldAny Any

or somesuch.

@andreasabel
Copy link
Member Author

What do you mean by type family here?

*Main> :m + Data.Monoid
*Main Data.Monoid> :info Any
newtype Any = Any {getAny :: Bool} 	-- Defined in ‘Data.Monoid’
instance Bounded Any -- Defined in ‘Data.Monoid’
instance Eq Any -- Defined in ‘Data.Monoid’
instance Ord Any -- Defined in ‘Data.Monoid’
instance Read Any -- Defined in ‘Data.Monoid’
instance Show Any -- Defined in ‘Data.Monoid’
instance Monoid Any -- Defined in ‘Data.Monoid’

This looks like a vanilla newtype to me.

@jyp
Copy link
Contributor
jyp commented Nov 28, 2017 via email

@andreasabel
Copy link
Member Author

Ah, ok, not the Data.Monoid.Any.

I have no experience with coerce in Haskell, haven't used that Any type before.

@jyp
Copy link
Contributor
jyp commented Nov 29, 2017 via email

@andreasabel
Copy link
Member Author

@jyp Can you give me a date by which you will have fixed this?

@jyp
Copy link
Contributor
jyp commented Jan 2, 2018 via email

@jyp jyp removed their assignment Jan 2, 2018
@andreasabel
Copy link
Member Author

Fixed by @bafain in 40cd766.

@andreasabel andreasabel added this to the 2.8.3 milestone Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants