0

I have a simple web app written with scotty. I would like to use fay to generate the front-end JS code and use shared types between the frontend and the backend.

At the moment, I run my app using cabal run: in my .cabal file I defined an "executable" and "build-depends" depends on base. When I include "fay" and "fay-base" in "build-depends", compilation fails because Prelude is ambigous.

I understand that "fay-base" is supposed to replace the standard prelude, but I still do want to use the standard prelude in the backend code.

So, how should I write my .cabal file and what language extensions should I use in my .hs files so that std Prelude and fay Prelude can coexist? Is this the right approach?

I am using fay-0.20.1.1.

lbolla
  • 5,387
  • 1
  • 22
  • 35

1 Answers1

1
  • You can have fay as a dependency, it's a normal Haskell package and doesn't cause any clashes.
  • fay-base doesn't replace base. It's Fay's version of base and can only be used with Fay code, and vice versa.
  • If you want to make sure fay-base is pulled in as a dependency you can depend on another fay package (such as the small fay-text to get fay-base included as a transitive dependency)

You have some options on when to build your fay code:

  • At program startup using Fay's API, or fay-builder which lets you specify fay options in your Cabal file (see this blog post but skip the part about custom cabal hooks!)
  • On every HTTP request, useful for development. You can use the Fay API, fay-builder, yesod-fay, snaplet-fay, or happstack-fay for this.
  • As a Cabal hook with a custom Setup.hs (Again, bad idea)
Adam Bergmark
  • 7,316
  • 3
  • 20
  • 23