foundation
foundation copied to clipboard
Stack template
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.
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 ?
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.
Looking good, couple of things:
- Use
RebindableSyntax
instead ofNoImplicitPrelude
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 infoundation
. I think we're quite close to avoidbase
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.
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
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
>>
andreturn
- 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
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 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.
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
...