 
    views
Installing Chocolatey and the Haskell Toolchain

Know your system's architecture. Open the basic system information viewer. It's located in the control panel at Control Panel > System and Security > System. On the system information panel, you'll see important information about your Windows system. Under the System section, you'll see System type. Just to the right of that label it will show you system architecture. (e.g. 32-bit or 64-bit)

Install Powershell. You will be using Powershell in a later step to install Chocolately. Click here to go to Powershell 7's latest release on GitHub. There are a lot of different versions on this page, but you should only focus on those versions compatible with Windows. They will look almost identical to PowerShell-7.x.y-win-ARCH.msi where x.y is the subversion--which you can ignore because they're all the same--and ARCH is either x64 or x86 (64-bit and 32-bit, respectively). You'll want to download the one that matches your system's architecture. For example, if the latest version is 7.0.2 and your machine is running 32-bit architecture (x86), you should downloadPowerShell-7.0.2-win-x86.msi. Likewise, for 64-bit architecture, the file will have x64 in place of x86.

Run the installer after it finishes downloading. You should not need to bother with the configuration; however, be sure to check the "Open Here" context menu add-on option. This will make it easier and faster to open Powershell to a specific directory.
Download the Windows Terminal from the Microsoft Store. This is essentially a wrapper for Powershell that modernizes the look and feel of Powershell while improving efficiency and adding some functionality including integration of other shells. Click here to go to the Windows Terminal download page.

Install Chocolatey. To get started, Run Windows Terminal as Administrator. If you do not run as Administrator, Chocolatey will fail to install because you need elevated privileges. Naturally, it follows any time you want to run Chocolatey, you must have elevated privileges (i.e. you must have your prompt running as Administrator).

Enter the commands below in sequential order. For reference, I have shown an example in the photo above.Set-ExecutionPolicy RemoteSigned Set-ExecutionPolicy Bypass -Scope Process -Force; iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
Restart Windows Terminal or run the command refreshenv to update the $Env:Path with the newly installed choco. You can check this by running choco --version. If you don't get an error, then everything is normal. For more information about installing Chocolatey please visit Installing Chocolatey

Install the Haskell tools. As noted on Haskell's website, you must install the haskell-dev package via Chocolatey. Before running choco make sure you've either restarted Windows Terminal or ran the commandrefreshenv so that choco will be in the $Env:Path. Using an elevated prompt, run the following command choco install haskell-dev -y

Run the refreshenv command. Once haskell-dev is finished installing, run refreshenv and test to see if they are in your path. You can do this by running ghc --version to check for the compiler.
Creating Your First Haskell Program
Open up a new blank document. You can use any text editor you'd like (e.g. vscode, atom, sublime, etc). Open up your text editor of choice with an empty document. You will save this document as hello.hs. The .hs extension is used to identify files containing Haskell source code.
Create first variable in Haskell. You need to define a variable called main. The haskell compiler is going to look for this when you compile your source code. main :: IO() The :: operator can be read as "has type". So you can read the above line of code as main "has type" IO() The IO() type is something called a Monad. I won't got into detail but you can read more on the Haskell wiki about monads.
Provide a value. The IO() Monad is used for Input/Output. So now that you have your variable main you just need to give it some value. main :: IO() main = putStrLn "Hello, world!" putStrLn is a function whose type is String -> IO(). That may look confusing at first, but it's rather simple. Think of the -> as a mapping from one type to another. That is, the putStrLn function maps a String to a Monad. Essentially, the function putStrLn takes a value of type String and returns a value of type IO(). This is why the typing checks out when you assign main to the value of putStrLn "Hello, world!"

Compile the program. Congratulations, you just wrote your first haskell program. All you have to do now is compile it. Open up Windows Terminal and navigate to the folder where you saved your hello.hs file. You can use the context menu option "Open Here" if you selected that option when install Powershell 7. Once there, you can begin the compilation process using the following command: ghc hello.hs -o hello The compile takes the source code hello.hs as input using the -o flag you can pass the name of what you want the output executable to be. In this case it's hello To run the program after run .\hello.exe note: It is important to have the .\ in front of hello.exe
 
 
     
     
     
     
     
     
     
     
                    
                     
             
             
                             
                             
                             
                             
                             
                             
                             
                            
Comments
0 comment