22

I'm trying to install gtk via cabal, however, I'm getting the following type errors when building it

[ 22 of 209] Compiling Graphics.UI.Gtk.Embedding.Plug ( dist/build/Graphics/UI/Gtk/Embedding/Plug.hs, dist/build/Graphics/UI/Gtk/Embedding/Plug.o )

Graphics/UI/Gtk/Embedding/Plug.chs:120:6: error:
    Couldn't match expected type ‘Ptr ()’
                with actual type ‘Maybe DrawWindow’
    In the first argument of ‘gtk_plug_new’, namely
      ‘(fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’
    In the second argument of ‘($)’, namely
      ‘gtk_plug_new
         (fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’

Graphics/UI/Gtk/Embedding/Plug.chs:137:6: error:
    Couldn't match expected type ‘Ptr ()’
                with actual type ‘Maybe DrawWindow’
    In the second argument of ‘\ (Display arg1) arg2
                                 -> withForeignPtr arg1
                                    $ \ argPtr1 -> gtk_plug_new_for_display argPtr1 arg2’, namely
      ‘(fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’
    In the second argument of ‘($)’, namely
      ‘(\ (Display arg1) arg2
          -> withForeignPtr arg1
             $ \ argPtr1 -> gtk_plug_new_for_display argPtr1 arg2)
         display
         (fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’

Graphics/UI/Gtk/Embedding/Plug.chs:151:3: error:
    Couldn't match type ‘Ptr ()’ with ‘Maybe DrawWindow’
    Expected type: IO (Maybe DrawWindow)
      Actual type: IO (Ptr ())
    In the second argument of ‘($)’, namely
      ‘(\ (Plug arg1)
          -> withForeignPtr arg1 $ \ argPtr1 -> gtk_plug_get_id argPtr1)
         (toPlug self)’
    In the expression:
      liftM toNativeWindowId
      $ (\ (Plug arg1)
           -> withForeignPtr arg1 $ \ argPtr1 -> gtk_plug_get_id argPtr1)
          (toPlug self)
Failed to install gtk-0.13.9
cabal: Error: some packages failed to install:
gtk-0.13.9 failed during the building phase. The exception was:
ExitFailure 1

To install this package, you need "gtk2hsC2hs" and the type errors are in .chs files, which presumably are generated from the gtk2hsC2hs tool. Is this a known problem with gtk2hsC2hs? Has anyone else been able to build this package? Anyone know of a solution?

I'm on Mac OS X Yosemite (10.10.4)

$ gtk2hsC2hs --version
C->Haskell Compiler, version 0.13.13 (gtk2hs branch) "Bin IO", 27 May 2012

$ cabal --version
cabal-install version 1.22.6.0
using version 1.22.4.0 of the Cabal library 

I've done a cabal update, so all my packages appear to be up to date. I've also tried building some of the older versions available from hackage, but I'm getting the same errors.

Edit

The errors in the generated files, seem to all deal with the FFI imports that are getting generated by gtk2hsC2hs. At the bottom of the file, I'm getting

foreign import ccall unsafe "gtk_plug_new"
  gtk_plug_new :: ((Ptr ()) -> (IO (Ptr Widget)))

It seems to consistently mix up Ptr() with Maybe DrawWindow. So is the generated type Ptr() incorrect, or is the usage of it incorrect?

Matt
  • 4,029
  • 3
  • 20
  • 37
  • Just a quick comment, haven't had time to look enough to write an answer: `.chs` files are not generated by `gtk2hsC2hs`; they are written by hand, and processed by `gtk2hsC2hs` to produce `.hs` files. If you want, you can look in those files; `cabal` stores them in the `dist` directory. There will be pragmas pointing back from the `.hs` file to the `.chs` file, which is how GHC knows where in the `.chs` file to point in its errors. – Daniel Wagner Aug 13 '15 at 22:42
  • Ok thanks for the tip. I'll look into that. – Matt Aug 13 '15 at 23:19

1 Answers1

24

This had a really simple solution.

cabal install gtk -fhave-quartz-gtk

It would be nice if this was more well documented, but hopefully this will help anyone else that ends up in a similar situation

Matt
  • 4,029
  • 3
  • 20
  • 37