Until now, I have had more opportunities to use interpreted and dynamically typed languages.
However, as I touched it, I felt that *** lacked "tightness" ***. *** I've heard the phrase "can be released with 70% perfection", so I think it's not so rigorous ***.
Of course, that's a good thing, and in the real world, I think it's stronger because it enables faster releases.
However, I felt like trying out compiler-type and static-typed languages to get a feel for the difference between the two. (Although there is also a preference problem that I feel that it is easier to handle if it is solid)
Moreover, as for object-oriented programming, I got a feel for it while touching JavaScript, Python, and PHP (I haven't said that I understood it), so I'm curious to touch something that is functional.
So I decided to study Haskell.
*** The code will be cleaner, and I'm expecting some nice side effects. *** ***
However, when I tried to get started, there were only a few articles about building an environment on Windows 10 Home (although there were quite a few Pro).
So, I will summarize *** about building a haskell environment on Windows 10 Home ***.
First, I will explain how to pull a haskell image with Docker and execute it from the command prompt.
Start with the steps to use Docker on Windows 10 Home. It will go to the point where you can execute haskell at once.
Control Panel → Programs → Enable or disable Windows functions
Enable "Linux Subsystem for Windows" in. (Then restart your PC)
https://hub.docker.com/editions/community/docker-ce-desktop-windows/
Click "Get stable".
When you start Docker, you will be scolded for "update the Linux kernel", so
https://docs.microsoft.com/en-us/windows/wsl/install-win10
Follow step 4 of the update. It will be fine and Docker will work.
(* It is possible that I was the only one who was messing around when building another environment, but the above page is organized in an easy-to-understand manner, so I feel that I should execute it in order.)
Open a command prompt and run the following in the appropriate directory:
$ docker pull haskell
You will get a haskell image.
afterwards,
$ docker run -it haskell
When you start the container with, it will enter the container without permission. (In short, you'll be ready to use haskell soon)
If you get Prelude> like this, you're successful.
You can do it right away.
In fact, VS Code allows you to play with haskell using an editor.
In other words, you can edit the hs file in the container or launch the terminal from VS Code without using the command prompt.
https://azure.microsoft.com/ja-jp/products/visual-studio-code/
Install VS Code from the link above.
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers
Install the VS Code extension "Remote-Containers" from the link above.
Create an appropriate directory and open it with VS Code.
Therefore, create a file called ".devcontainer.json" and write the following.
json:.devcontainer.json
{
"name" : "haskell",
"images" : "haskell",
"extensions" : "haskell.haskell"
}
This file manages the Docker image to be pulled and its settings. In short, it's a substitute for Dockerfile.
VS Code seems to manage the setting system with a json file.
Then press "Green Button at Bottom Left"-> "Remote-Containers: Open Folder Container ..." in the order of the images.
With this, it will do everything from pulling the Docker image to launching the container.
From the second time onward, you will be asked if you want to launch the container at the bottom right. You can restart it by pressing "Reopen in Container".
If you execute the above, it will enter the container without permission and will launch up to the terminal without permission. VS Code is convenient.
(It was quite confusing at first, but the command prompt is Windows, the terminal is Linux CLI. It's a little complicated. It seems that Windows powershell is an extension of the function based on command prompt)
At this point you can use haskell.
At the terminal that came out below
$ stack ghci
To execute. Now you can run haskell interactively, just as you did at the command prompt.
By the way, ghci is an abbreviation for "Glasgow Haskell Compiler Interface". Haskell was developed at the University of Glasgow, a university in the north of England.
It's nice to run it interactively, but since I'm using an editor, I want to write code in a file and read it.
Haskell manages by writing code in the hs file.
For example, create a file called "hello_world.hs" and write the following code.
hello_world.hs
main = putStrLn "Hello world!"
Then at the terminal
$ stack runghc hello_world.hs
To execute. Then, it will do everything from compilation to execution.
Now it's sunny and you can run haskell!
This time it was about the procedure to run haskell on Windows 10 Home. It was almost how Docker works.
I think I'll play with it as a hobby from now on, so I may write haskell material from time to time.
I want to write math material soon ~
Recommended Posts