Building a haskell environment with Docker + VS Code on Windows 10 Home

Introduction

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 ***.

environment

When using Docker

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.

① Enable "Linux subsystem for Windows"

Control Panel → Programs → Enable or disable Windows functions

サブシステム.png

Enable "Linux Subsystem for Windows" in. (Then restart your PC)

② Install Docker Desktop on Windows Home

https://hub.docker.com/editions/community/docker-ce-desktop-windows/

Click "Get stable".

③ Start Docker

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.

step4.png

(* 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.)

④ Pull the Haskell image

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)

haskell.png

If you get Prelude> like this, you're successful.

You can do it right away.

haskell例.png

Method using Docker + VS Code

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.

① Install VS Code

VScodeインスト―ル.png

https://azure.microsoft.com/ja-jp/products/visual-studio-code/

Install VS Code from the link above.

② Install Remote-Containers

vscode拡張.png

https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers

Install the VS Code extension "Remote-Containers" from the link above.

③ Launch the container

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.

container実行.png

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".

devcontainer.png

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)

devcontainer立ち上げ.png

④ Execute haskell

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.

実行.png

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.

⑤ Edit & execute hs file

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.

hello.png

Now it's sunny and you can run haskell!

finally

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

Building a haskell environment with Docker + VS Code on Windows 10 Home
Connect with VS Code from a Windows client to Docker on another server
Build a Docker-based development environment on Windows 10 Home 2020 ver. Part 2 VS Code should make the Docker development environment comfortable
Create Spring Boot environment with Windows + VS Code
Build a Java development environment with VS Code
Build a Doker-based development environment on Windows 10 Home 2020 ver. Part 1 Until WSL2-based Docker build
Build Java development environment with VS Code on Mac
Run VS Code on Docker
Build ruby debug environment with VS Code of Windows 10
Build Java development environment with WSL2 Docker VS Code
[Environment construction] Build a Java development environment with VS Code!
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
Create a Java (Gradle) project with VS Code and develop it on a Docker container
Create a Java (Maven) project with VS Code and develop it on a Docker container
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Try debugging natural language processing on Windows. with VS Code
Create a Vue3 environment with Docker!
Build a Node.js environment with Docker
Try Docker on Windows Home (September 2020)
Getting Started with Docker with VS Code
Using Docker on Windows10 Home WSL2
Workspace setting location when connecting remotely with VS Code and working on a Docker container
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Prepare a transcendentally simple PHP & Apache environment on Mac with Docker
Building Rails 6 and PostgreSQL environment with Docker
Build a PureScript development environment with Docker
Create a MySQL environment with Docker from 0-> 1
[Ruby] Building a Ruby development environment on Ubuntu
Build a Wordpress development environment with Docker
Build Redmine code reading environment on Docker
[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code
Build an environment with Docker on AWS
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
A memorandum when IME cannot be turned on with VS Code (Ubuntu 20.04)
A memo that enabled VS Code + JUnit 5 to be used on Windows 10
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
[Memo] Create a CentOS 8 environment easily with Docker
Self-hosting with Docker of AuteMuteUs in Windows environment
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Build a Laravel / Docker environment with VSCode devcontainer
Environment construction command memo with Docker on AWS
Building a Ruby environment for classes on Mac
Building OpenPose (Pytorch_Realtime_Multi-Person_Pose_Estimation) environment on Docker: training part
Notes on building Rails6 / PostgreSQL with Docker Compose
Prepare a scraping environment with Docker and Java
Try debugging a Java program with VS Code
Create a Spring Boot development environment with docker
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2
A memorandum when building an environment with Ruby3.0 x Rails6.1 x Docker x CentOS Stream
Build a development environment to create Ruby on Jets + React apps with Docker
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
Lombok with VS Code
Easily build a Vue.js environment with Docker + Vue CLI
The procedure I did when I prepared the environment of gradle + Java with VS Code (Windows 10)
[Note] Build a Python3 environment with Docker in EC2
I tried using Docker Desktop for Windows on Windows 10 Home
[Note] Create a java environment from scratch with docker
How to build Java development environment with VS Code
M.S. docker on Windows