2

I installed threepenny-gui by setting up a cabal sandbox and running

cabal install threepenny-gui -fbuildExamples

which seemed to work fine. The examples were found in the .cabal-sandbox/bin-folder and they worked perfectly.

After that I looked at the source code of the examples and tried to run them using the runhaskell and ghci -scripts and got the following errors

>./runhaskell CRUD.hs 
../src/Foreign/JavaScript/Marshal.hs:62:7: Warning:
In the use of ‘Data.Aeson.Encode.fromValue’
(imported from Data.Aeson.Encode):
Deprecated: "Use 'encodeToTextBuilder' instead"

../src/Graphics/UI/Threepenny/Core.hs:349:43:
Could not deduce (JS.FromJS a) arising from a use of ‘get’
from the context (ToJS a, FFI (JSFunction a))
  bound by the type signature for
             fromObjectProperty :: (ToJS a, FFI (JSFunction a)) =>
                                   String -> Attr Element a
  at ../src/Graphics/UI/Threepenny/Core.hs:348:23-78
Possible fix:
  add (JS.FromJS a) to the context of
    the type signature for
      fromObjectProperty :: (ToJS a, FFI (JSFunction a)) =>
                            String -> Attr Element a
In the first argument of ‘mkReadWriteAttr’, namely ‘get’
In the expression: mkReadWriteAttr get set
In an equation for ‘fromObjectProperty’:
    fromObjectProperty name
      = mkReadWriteAttr get set
      where
          set v el = runFunction $ ffi ("%1." ++ name ++ " = %2") el v
          get el = callFunction $ ffi ("%1." ++ name) el

with both of the scripts. I also tried running/compiling the sample program from http://hackage.haskell.org/package/threepenny-gui-0.6.0.1/docs/Graphics-UI-Threepenny.html which resulted in the following errors

> ghci test.hs 
GHCi, version 7.8.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.

test.hs:3:18:
Could not find module ‘Graphics.UI.Threepenny’
Use -v to see a list of the files searched for.

test.hs:4:25:
Could not find module ‘Graphics.UI.Threepenny.Core’
Use -v to see a list of the files searched for.
Failed, modules loaded: none.

My experience using external libraries with Haskell is very limited and the latter one clearly comes from ghc not knowing where to look for these packages.

How can I provide the right paths to ghc and get the Core.hs to work properly?

655321
  • 195
  • 6
  • Are you running in the sandbox environment via `cabal exec`. If you aren't the code is being run outside the sandbox. The cabal sandbox only applies to cabal commands unless you use cabal exec. – Alex May 09 '15 at 10:51
  • Hey, thanks! I got it to compile with `cabal exec ghc test.hs` and the same for the examples. This sandbox stuff is a bit confusing sometimes... – 655321 May 09 '15 at 11:08
  • I'm still a bit confused about using this package in my own code. I can now compile code in the threepenny-gui directory (with the sandbox set correctly), but if I wanted to do it somewhere else (for example use threepenny-gui with some code I have in `~/myGreatProject/`), how would I set the sandbox up then? – 655321 May 09 '15 at 11:24
  • @655321 In the `~/myGreatProject` folder, you simply set up a new sandbox with `cabal sandbox init` and install the packages you want to use within the sandbox environment. In particular, you would execute the command `cabal install threepenny-gui` in the folder in order to install the threepenny-gui package, which you can then use from the sandbox. – Heinrich Apfelmus May 10 '15 at 07:55
  • @655321 The error that you've encountered when running `./runhaskell CRUD.hs` seems strange to me. Can you run `./ghci -v CRUD.hs` and show the output? – Heinrich Apfelmus May 10 '15 at 07:57
  • Ok, thanks, the sandbox thing was after all easier than I thought. Running the command you asked gives the following output http://pastebin.com/qFjfJq1a. – 655321 May 10 '15 at 15:25
  • @655321 The error that you've encountered while running `./ghci` is due to a problem with your source tree. The `./ghci` and `./runhaskell` scripts try to recompile Threepenny from the local `src` folder, which is not necessarily the same version of Threepenny as the one that you have installed. This particular problem was [fixed already](https://github.com/HeinrichApfelmus/threepenny-gui/commits/master/src/Graphics/UI/Threepenny/Core.hs). It looks like your `src` folder still contains the old Threepenny version 0.5.0.0 or thelike. – Heinrich Apfelmus May 12 '15 at 08:23

0 Answers0