{"id":8198,"date":"2020-06-12T22:03:20","date_gmt":"2020-06-12T22:03:20","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=8198"},"modified":"2020-06-12T22:03:20","modified_gmt":"2020-06-12T22:03:20","slug":"getting-started-with-cabal","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/getting-started-with-cabal\/","title":{"rendered":"Getting Started with Cabal"},"content":{"rendered":"<p>Cabal is the Haskell package and build tool. <\/p>\n<p>The following are a few of the &#8220;getting started&#8221; commands.<\/p>\n<p><strong>What version do you have of Cabal?<\/strong><\/p>\n<p>Run the following<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal --version\r\n<\/pre>\n<p><strong>Check for updates to Cabal<\/strong><\/p>\n<p>You can check <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal new-install Cabal cabal-install\r\n<\/pre>\n<p><strong>Check for package updates<\/strong><\/p>\n<p>This command will pull the latest package list from hackage.haskell.org<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal update\r\n<\/pre>\n<p><strong>Creating a new project<\/strong><\/p>\n<p>We can create a new Haskell project using<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal init\r\n<\/pre>\n<p>This will create a Main.hs, Setup.hs and a .cabal file for your configurations. We can then edit the .cabal file or we can run the interactive version and supply details using<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal init -i\r\n<\/pre>\n<p><strong>Building our project<\/strong><\/p>\n<p>We can build our project by simply using <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal build\r\n<\/pre>\n<p><strong>Running our project<\/strong><\/p>\n<p>To run (or build and run)<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal run\r\n<\/pre>\n<p><strong>Cleaning our project<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal clean\r\n<\/pre>\n<p><strong>Running the ghci repl<\/strong><\/p>\n<p>You can run ghci by simply typing<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nghci\r\n<\/pre>\n<p>Or you can run the ghci that&#8217;s available via cabal using<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal repl\r\n<\/pre>\n<p><strong>Adding a library<\/strong><\/p>\n<p>We can download and install package from <a href=\"http:\/\/hackage.haskell.org\/\" rel=\"noopener noreferrer\" target=\"_blank\">The Haskell Package Repository<\/a> using the command<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ncabal install --lib QuickCheck HUnit\r\n<\/pre>\n<p>This installs the packages <em>QuickCheck<\/em> and <em>HUnit<\/em> from the package repository. The &#8211;lib is used for packages which do not contain an executable (i.e. a library package). We can also install .gz packages by specifying a file location or URL.<\/p>\n<p>Packages are then stored on Windows in <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n%USERPROFILE%\\AppData\\Roaming\\cabal\\store\\ghc-8.10.1\r\n<\/pre>\n<p><strong>References<\/strong><\/p>\n<p><a href=\"https:\/\/www.haskell.org\/cabal\/users-guide\/\" rel=\"noopener noreferrer\" target=\"_blank\">Welcome to the Cabal User Guide<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cabal is the Haskell package and build tool. The following are a few of the &#8220;getting started&#8221; commands. What version do you have of Cabal? Run the following cabal &#8211;version Check for updates to Cabal You can check cabal new-install Cabal cabal-install Check for package updates This command will pull the latest package list from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[296,295],"tags":[],"class_list":["post-8198","post","type-post","status-publish","format-standard","hentry","category-cabal","category-haskell"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=8198"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8198\/revisions"}],"predecessor-version":[{"id":8213,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8198\/revisions\/8213"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=8198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=8198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=8198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}