compiling-to-categories / concat

Compiling to Categories
http://conal.net/papers/compiling-to-categories
BSD 3-Clause "New" or "Revised" License
436 stars 50 forks source link

Dictionary construction failures and GHC 8.2.2 #42

Closed conal closed 1 year ago

conal commented 6 years ago

After this commit getting past issue #41 (with ctev_nosh = WOnly), I get a little further. The next error message I get is from the plugin itself, reporting that dictionary construction failed:

ghc: panic! (the 'impossible' happened)
  (GHC version 8.2.2 for x86_64-apple-darwin):
    ccc - couldn't build dictionary for
  exr @ (->) @ Double @ Double :: (ProductCat (->),
                                   Ok2 (->) Double Double) =>
                                  (->):
  no bindings
  Call stack:
      CallStack (from HasCallStack):
        prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable
        callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable
        pprPanic, called at src/ConCat/Plugin.hs:1132:23 in concat-plugin-0.3.0.0-EuTio8PFqXo3nKN9zOJI1b:ConCat.Plugin

I tested by running stack build :misc-examples with only the following example enabled in test/Examples.hs:

  , runSynCirc "add"         $ toCcc $ (+) @R
kosmikus commented 6 years ago

Right, this is the error we were stuck with originally. I'll try to look at this again. I'm not completely convinced the this is really a problem in buildDictionary though, because I think the trace of rules fired diverges between the GHC versions even before.

conal commented 6 years ago

The failure here is unexpected, since the needed constraint ((ProductCat (->), Ok2 (->) Double Double)) holds (is inhabited). Another oddity is that the type isn't even well-kinded, since it ends in (->) which doesn't have kind *.

philzook58 commented 6 years ago

Hi, This may or may not be related to this issue. I'm using GHC 8.0.2 and getting a similar error message.

I was giving the library a try and couldn't get my first custom Category instance to work, although calling toCcc' does work for simply translating a lambda to itself. Do I need to define all the instance like CoproductCat and UnitCat to get the plugin to work? Or is this a bug?

Thanks! Love what this project is doing!

https://github.com/philzook58/concat-template/blob/master/app/Main.hs

  (GHC version 8.0.2 for x86_64-apple-darwin):
    ccc - couldn't build dictionary for
  id @ FreeCat @ Any :: (Category FreeCat, Ok FreeCat Any) =>
                        FreeCat Any Any:
  free id types: [Category FreeCat]
instance Category (FreeCat) where
  -- type Ok (FreeCat) = ()
  id  = Id
  (.) = Comp
data FreeCat a b where
   Id :: FreeCat a a
   Comp :: FreeCat b c -> FreeCat a b -> FreeCat a c
   Par :: FreeCat a b -> FreeCat c d -> FreeCat (a,c) (b,d)
   Exl :: FreeCat (a,b) a
   Exr :: FreeCat (a,b) b
   Dup :: FreeCat a (a,a)
main :: IO ()
main = do
    putStrLn $ show $ (toCcc' (\(x, y) -> (y, x)))  ("larry", "fred")-- Conversion of lambda to itself. Seems to work
    -- putStrLn $ show $ freecat $ ((toCcc' (\x -> x))) -- Does not work
    putStrLn $ show $ (((toCcc' (\x -> x))) :: FreeCat a a ) -- does not work
conal commented 6 years ago

@philzook58 I bet the problem here is issue #2.

adamgundry commented 6 years ago

This issue was fixed by #45, right?

conal commented 6 years ago

Hm. I don't know.

mikesperber commented 1 year ago

There's been lots of work on dictionary construction, and no current problems are known.