foundation icon indicating copy to clipboard operation
foundation copied to clipboard

Stack template

Open flip111 opened this issue 8 years ago • 8 comments

It would be nice to have a stack template to start a new project with Foundation, there is actually quite a few things to change from the standard simple project.

flip111 avatar Jan 15 '17 17:01 flip111

This is a great idea; I've not looked at what it involves, but that would be really cool. Do you want to tackle this @flip111 or detail what you think need to be added ?

vincenthz avatar Jan 16 '17 09:01 vincenthz

I was looking to create such a template but i'm just not sure what all the best options are for foundation so i think it's good if other people can look at it as well. What i have so far is based on the simple template. Then i modified the following:

in the cabal file

executable {{name}}
  hs-source-dirs:      src
  main-is:             Main.hs
  default-language:    Haskell2010
  default-extensions:  NoImplicitPrelude
                     , OverloadedStrings
  build-depends:       base >= 4.7 && < 5
                     , foundation

main file

module Main where

import Foundation

main :: IO ()
main = do
  putStrLn "hello " <> "world"

so maybe base is no longer required? There are also a lot of other options in these files and you can write other files as well so if Foundation need anything more specific it should be easy to add. One thing that is missing is that stack automatically downloads and installs foundation, this is still a manual step. Oh i changed the main.hs file just to show that concatenating strings works differently now and to "show off" a piece of foundation technology.

flip111 avatar Jan 16 '17 12:01 flip111

Looking good, couple of things:

  • Use RebindableSyntax instead of NoImplicitPrelude in .cabal file: that allow to use our own ifThenElse, numbers, etc..
  • base is not strictly needed so could be removed, although in practice for now it's very like that you will pull some stuff from base since not everything is yet present in foundation. I think we're quite close to avoid base altogether; couple of months top.
  • you're probably missing some () around the string concatenation, but overall that's a good idea to put the <> change in light in an example main.

vincenthz avatar Jan 16 '17 13:01 vincenthz

cabal file

executable {{name}}
  hs-source-dirs:      src
  main-is:             Main.hs
  default-language:    Haskell2010
  default-extensions:  RebindableSyntax
                     , OverloadedStrings
  build-depends:       foundation

main file

module Main where

import Foundation

main :: IO ()
main = do
  putStrLn $ "hello " <> "world"

.ghci

{-# START_FILE .ghci #-}
:set -XOverloadedStrings

flip111 avatar Jan 16 '17 16:01 flip111

Some issues i noticed:

  • Foundation is not on hackage lts so it's downloading a nightly instead of lts
  • When RebindableSyntax is used then starting ghci causes not in scope for >> and return
  • When base is not in the cabal file ghci gives errors like: note in scope System.IO.hSetBuffering
  • ghci throws a warning, this issue tracks it https://github.com/commercialhaskell/stack/issues/2947

I think for now it's better to require base and use NoImplicitPrelude instead of RebindableSyntax. When the mention features are fixed then we can just make a "true" foundation stack template

flip111 avatar Jan 23 '17 16:01 flip111

You mentioned that when RebindableSyntax is switched on stack ghci doesn't work. How do you work around that without changing the behaviour of the library?

DavidM-D avatar May 22 '17 13:05 DavidM-D

@DavidM-D i'm assuming that this is a dependency of ghci on the current base and ghci itself needs an update to be compatible with foundation + RebindableSyntax. Anyway i'm not the person to ask, i just reported what i found using trial & error.

flip111 avatar May 22 '17 13:05 flip111

I'm pretty sure someone open the same issue on ghc couple of months back, but for some reason I couldn't find it.

Otherwise as a, crappy, but working workaround:

$ stack ghci --ghci-options -XNoRebindableSyntax --ghci-options -fobject-code --no-load
> :set -XRebindableSyntax
> :load Foundation
...

vincenthz avatar May 23 '17 08:05 vincenthz