(window.webpackJsonp=window.webpackJsonp||[]).push([[1224],{1632:function(a,s,e){"use strict";e.r(s);var t=e(31),r=Object(t.a)({},(function(){var a=this,s=a.$createElement,e=a._self._c||s;return e("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[e("h1",{attrs:{id:"stack"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#stack"}},[a._v("#")]),a._v(" Stack")]),a._v(" "),e("h2",{attrs:{id:"profiling-with-stack"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#profiling-with-stack"}},[a._v("#")]),a._v(" Profiling with Stack")]),a._v(" "),e("p",[a._v("Configure profiling for a project via "),e("code",[a._v("stack")]),a._v(". First build the project with the "),e("code",[a._v("--profile")]),a._v(" flag:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("build")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[a._v("--profile")]),a._v("\n\n")])])]),e("p",[a._v("GHC flags are not required in the cabal file for this to work (like "),e("code",[a._v("-prof")]),a._v("). "),e("code",[a._v("stack")]),a._v(" will automatically turn on profiling for both the library and executables in the project. The next time an executable runs in the project, the usual "),e("code",[a._v("+RTS")]),a._v(" flags can be used:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("exec")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[a._v("-- my-bin +RTS -p")]),a._v("\n\n")])])]),e("h2",{attrs:{id:"structure"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#structure"}},[a._v("#")]),a._v(" Structure")]),a._v(" "),e("h3",{attrs:{id:"file-structure"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#file-structure"}},[a._v("#")]),a._v(" File structure")]),a._v(" "),e("p",[a._v("A simple project has the following files included in it:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[a._v("➜ "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("helloworld")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("ls")]),a._v(" \n"),e("span",{pre:!0,attrs:{class:"token constant"}},[a._v("LICENSE")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("Setup"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(".")]),a._v("hs")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("helloworld")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(".")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("cabal")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("src")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(".")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("yaml")]),a._v("\n\n")])])]),e("p",[a._v("In the folder "),e("code",[a._v("src")]),a._v(" there is a file named "),e("code",[a._v("Main.hs")]),a._v('. This is the "starting point" of the '),e("code",[a._v("helloworld")]),a._v(" project. By default "),e("code",[a._v("Main.hs")]),a._v(' contains a simple "Hello, World!" program.')]),a._v(" "),e("p",[e("strong",[a._v("Main.hs")])]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[a._v("module")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token constant"}},[a._v("Main")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[a._v("where")]),a._v("\n\n"),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("main")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("::")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token constant"}},[a._v("IO")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n"),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("main")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[a._v("do")]),a._v("\n "),e("span",{pre:!0,attrs:{class:"token builtin"}},[a._v("putStrLn")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[a._v('"hello world"')]),a._v("\n\n")])])]),e("h3",{attrs:{id:"running-the-program"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#running-the-program"}},[a._v("#")]),a._v(" Running the program")]),a._v(" "),e("p",[a._v("Make sure you are in the directory "),e("code",[a._v("helloworld")]),a._v(" and run:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("build")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("#")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token constant"}},[a._v("Compile")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("the")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("program")]),a._v("\n"),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("exec")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("helloworld")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("#")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token constant"}},[a._v("Run")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("the")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("program")]),a._v("\n"),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("#")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("prints")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[a._v('"hello world"')]),a._v("\n\n")])])]),e("h2",{attrs:{id:"build-and-run-a-stack-project"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#build-and-run-a-stack-project"}},[a._v("#")]),a._v(" Build and Run a Stack Project")]),a._v(" "),e("p",[a._v('In this example our project name is "helloworld" which was created with '),e("code",[a._v("stack new helloworld simple")])]),a._v(" "),e("p",[a._v("First we have to build the project with "),e("code",[a._v("stack build")]),a._v(" and then we can run it with")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("exec")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("helloworld")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("-")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("exe")]),a._v("\n\n")])])]),e("h2",{attrs:{id:"viewing-dependencies"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#viewing-dependencies"}},[a._v("#")]),a._v(" Viewing dependencies")]),a._v(" "),e("p",[a._v("To find out what packages your project directly depends on, you can simply use this command:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("list")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("-")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("dependencies")]),a._v("\n\n")])])]),e("p",[a._v("This way you can find out what version of your dependencies where actually pulled down by stack.")]),a._v(" "),e("p",[a._v("Haskell projects frequently find themselves pulling in a lot of libraries indirectly, and sometimes these external dependencies cause problems that you need to track down. If you find yourself with a rogue external dependency that you'd like to identify, you can grep through the entire dependency graph and identify which of your dependencies is ultimately pulling in the undesired package:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("dot")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[a._v("--external | grep template-haskell")]),a._v("\n\n")])])]),e("p",[e("code",[a._v("stack dot")]),a._v(" prints out a dependency graph in text form that can be searched. It can also be viewed:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("dot")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[a._v("--external | dot -Tpng -o my-project.png")]),a._v("\n\n")])])]),e("p",[a._v("You can also set the depth of the dependency graph if you want:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("dot")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[a._v("--external --depth 3 | dot -Tpng -o my-project.png")]),a._v("\n\n")])])]),e("h2",{attrs:{id:"installing-stack"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#installing-stack"}},[a._v("#")]),a._v(" Installing Stack")]),a._v(" "),e("p",[e("strong",[a._v("Mac OSX")])]),a._v(" "),e("p",[a._v("Using "),e("a",{attrs:{href:"http://brew.sh/",target:"_blank",rel:"noopener noreferrer"}},[a._v("Homebrew"),e("OutboundLink")],1),a._v(":")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("brew")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("install")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("haskell")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("-")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v("\n\n")])])]),e("h2",{attrs:{id:"creating-a-simple-project"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#creating-a-simple-project"}},[a._v("#")]),a._v(" Creating a simple project")]),a._v(" "),e("p",[a._v("To create a project called "),e("strong",[a._v("helloworld")]),a._v(" run:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("new")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("helloworld")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("simple")]),a._v("\n\n")])])]),e("p",[a._v("This will create a directory called "),e("code",[a._v("helloworld")]),a._v(" with the files necessary for a Stack project.")]),a._v(" "),e("h2",{attrs:{id:"stack-install"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#stack-install"}},[a._v("#")]),a._v(" Stack install")]),a._v(" "),e("p",[a._v("By running the command")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stack")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("install")]),a._v(" \n\n")])])]),e("p",[a._v("Stack will copy a executable file to the folder")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("/")]),e("span",{pre:!0,attrs:{class:"token constant"}},[a._v("Users")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("/<")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("yourusername")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">/.")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("local")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("/")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("bin")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("/")]),a._v("\n\n")])])]),e("h2",{attrs:{id:"stackage-packages-and-changing-the-lts-resolver-version"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#stackage-packages-and-changing-the-lts-resolver-version"}},[a._v("#")]),a._v(" Stackage Packages and changing the LTS (resolver) version")]),a._v(" "),e("p",[e("a",{attrs:{href:"https://www.stackage.org/",target:"_blank",rel:"noopener noreferrer"}},[a._v("Stackage"),e("OutboundLink")],1),a._v(" is a repository for Haskell packages. We can add these packages to a stack project.")]),a._v(" "),e("h3",{attrs:{id:"adding-lens-to-a-project"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#adding-lens-to-a-project"}},[a._v("#")]),a._v(" Adding lens to a project.")]),a._v(" "),e("p",[a._v("In a stack project, there is a file called "),e("code",[a._v("stack.yaml")]),a._v(". In "),e("code",[a._v("stack.yaml")]),a._v(" there is a segment that looks like:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("resolver")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v(":")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("lts")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("-")]),e("span",{pre:!0,attrs:{class:"token number"}},[a._v("6.8")]),a._v("\n\n")])])]),e("p",[a._v("Stackage keeps a list of packages for every revision of "),e("code",[a._v("lts")]),a._v(". In our case we want the list of packages for "),e("code",[a._v("lts-6.8")]),a._v(" To find these packages visit:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("https")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("://")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("www")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(".")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("stackage")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(".")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("org")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("/")]),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("lts")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("-")]),e("span",{pre:!0,attrs:{class:"token number"}},[a._v("6.8")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("#")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[a._v("if")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("a")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("different")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("version")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("is")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("used")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(",")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("change")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[a._v("6.8")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("to")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("the")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("correct")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("resolver")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("number")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(".")]),a._v("\n\n")])])]),e("p",[a._v("Looking through the packages, there is a "),e("a",{attrs:{href:"https://www.stackage.org/lts-6.8/package/lens-4.13",target:"_blank",rel:"noopener noreferrer"}},[a._v("Lens-4.13"),e("OutboundLink")],1),a._v(".")]),a._v(" "),e("p",[a._v("We can now add the language package by modifying the section of "),e("code",[a._v("helloworld.cabal")]),a._v(":")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v("\n build-depends: base >= 4.7 && < 5\n\n")])])]),e("p",[a._v("to:")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v("\n build-depends: base >= 4.7 && 5,\n lens == 4.13\n\n")])])]),e("p",[a._v("Obviously, if we want to change a newer LTS (after it's released), we just change the resolver number, eg.:")]),a._v(" "),e("div",{staticClass:"language-hs extra-class"},[e("pre",{pre:!0,attrs:{class:"language-hs"}},[e("code",[e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("resolver")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v(":")]),a._v(" "),e("span",{pre:!0,attrs:{class:"token hvariable"}},[a._v("lts")]),e("span",{pre:!0,attrs:{class:"token operator"}},[a._v("-")]),e("span",{pre:!0,attrs:{class:"token number"}},[a._v("6.9")]),a._v("\n\n")])])]),e("p",[a._v("With the next "),e("code",[a._v("stack build")]),a._v(" Stack will use the LTS 6.9 version and hence download some new dependencies.")])])}),[],!1,null,null,null);s.default=r.exports}}]);