A bit of a background that leads to the question I have.
I am learning Yesod, and I am reading the Yesod book. In the Basics section of the book, the instructions on how to get a basic Yesod application was given. The instructions basically says put this in a file:
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Yesod
data HelloWorld = HelloWorld
mkYesod "HelloWorld" [parseRoutes|
/ HomeR GET
|]
instance Yesod HelloWorld
getHomeR :: Handler Html
getHomeR = defaultLayout [whamlet|Hello World!|]
main :: IO ()
main = warp 3000 HelloWorld
and run it with runhaskell helloworld.hs
or stack runghc helloworld.hs
. I did exactly this and that did not work. I get an error about yesod
cannot be found. Apparently there is step I should have ran prior to this, which is not mentioned in the basic section. I found that step in the quickstart guide here https://www.yesodweb.com/page/quickstart
And the instruction in there basically says
- install stack
- Create a new scaffolded site: stack new my-project yesodweb/sqlite && cd my-project
- Install the yesod command line tool: stack install yesod-bin --install-ghc
- Build libraries: stack build
- Launch devel server: stack exec -- yesod devel
- View your Yesod site at http://localhost:3000/
I followed all of this and it seems to work, but now back to running the helloworld.hs
file in the basic section. I understand above that the command stack install yesod-bin --install-ghc
installs a yesod
. So I thought that would fix the problem of Yesod
not found. I went back to the directory where I had the helloworld.hs
file and ran stack runghc helloworld.hs
but that did not work.
It only worked when I moved helloworld.hs
into the my-project
project I created when I followed the quickstart guide. So my question now is, what exactly does the command stack runghc helloworld.hs
and why is it that the command only works when I have the helloworld.hs
file in a stack project?