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

Example in Data.Derive.UniplateDirect fails #26

Open
ddssff opened this issue Sep 18, 2017 · 8 comments
Open

Example in Data.Derive.UniplateDirect fails #26

ddssff opened this issue Sep 18, 2017 · 8 comments

Comments

@ddssff
Copy link

ddssff commented Sep 18, 2017

{-# OPTIONS_GHC -F -pgmFderive -optF-F -optF-F #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}

import Data.Derive.UniplateDirect
import Data.Generics.Uniplate.Direct

data Foo a = Foo a (Bool, a)

{-!
deriving instance UniplateDirect (Foo Int)
deriving instance UniplateDirect (Bool, Int) Int
deriving instance UniplateDirect (Foo Int) Int
!-}

When loaded or compiled:

λ> :load "/tmp/test.hs"
[    1 of 1] Compiling Main             ( /tmp/test.hs, interpreted )

/tmp/ghced76_0/ghc_11.hspp:17:10: error:
    • Expecting one fewer argument to ‘Uniplate Foo’
      Expected kind ‘* -> Constraint’,
        but ‘Uniplate Foo’ has kind ‘Constraint’
   • In the instance declaration for ‘Uniplate Foo Int’

/tmp/ghced76_0/ghc_11.hspp:17:19: error:
    • Expecting one more argument to ‘Foo’
      Expected a type, but ‘Foo’ has kind ‘* -> *’
    • In the first argument of ‘Uniplate’, namely ‘Foo’
      In the instance declaration for ‘Uniplate Foo Int’

/tmp/ghced76_0/ghc_11.hspp:25:10: error:
    • Expecting one fewer argument to ‘Biplate Int Foo’
      Expected kind ‘* -> Constraint’,
        but ‘Biplate Int Foo’ has kind ‘Constraint’
    • In the instance declaration for ‘Biplate Int Foo Int’

/tmp/ghced76_0/ghc_11.hspp:25:22: error:
    • Expecting one more argument to ‘Foo’
      Expected a type, but ‘Foo’ has kind ‘* -> *’
    • In the second argument of ‘Biplate’, namely ‘Foo’
      In the instance declaration for ‘Biplate Int Foo Int’
Failed, modules loaded: none.
@ndmitchell
Copy link
Owner

Do you actually use UniplateDirect? I generally switched to Uniplate.Data for most of my programs, which has the advantage of no instances required. Doesn't sound too hard, but really looking for other people to fix it, as per #6 (which it seems you've already found).

@ddssff
Copy link
Author

ddssff commented Sep 23, 2017

I was looking for the option of using UniplateDirect because what I have now is incredibly slow. I will give the fix a shot, and if I can do it I will be more confident about taking on #6.

@ndmitchell
Copy link
Owner

Have you read https://hackage.haskell.org/package/uniplate-1.6.12/docs/Data-Generics-Uniplate-Data.html, particularly the part about UNIPLATE_VERBOSE? Table computation can give a massive speed difference, so setting it to -1 is worthwhile to see if that's an initial issue.

@ddssff
Copy link
Author

ddssff commented Sep 26, 2017

Neil, do you know why loading Example.hs gives me

derive: Don't know how to derive type class: Eq

@ndmitchell
Copy link
Owner

Yep, in the last release I ripped out everything GHC could derive itself on the basis people should use GHC in preference to derive and I could avoid porting those definitions to the new Haskell-src-exts library. I suspect I didn't update the example.

@ddssff
Copy link
Author

ddssff commented Sep 28, 2017

Lately I've become leery of GHC.Generics - it creates huge declarations when there are a lot of constructors, and the results take a long time to compile.

@ndmitchell
Copy link
Owner

I meant that Eq is baked into the compiler, not just that it could be done using Generics. That said, a Generic solution while taking a long time to compile is often to be preferred to a preprocessor.

@ddssff
Copy link
Author

ddssff commented Oct 2, 2017

On the other hand, I just eliminated all the Generic instances from our GHCJS application (using custom implementations of deriveSerialize and deriveJSON instead) and the javascript executable size dropped from 52M to 36M. I wonder if there will be a performance hit?

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

2 participants