๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“  archive

[Haskell Tutorial] Hello World!

by HandHand 2022. 11. 28.

 

๐Ÿ’ก ํ•ด๋‹น ํฌ์ŠคํŠธ๋Š” Learn Haskell by building a blog generator ๋ฅผ ์ •๋ฆฌํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

 

๐Ÿ“Œ Haskell ๊ฐœ๋ฐœํ™˜๊ฒฝ ์„ค์ •

๊ฐ€์žฅ ๋จผ์ € GHCup ์„ ์„ค์น˜ํ•ด์ค๋‹ˆ๋‹ค.

Haskell ๊ฐœ๋ฐœ์— ํ•„์š”ํ•œ HLS, ghc ๋“ฑ์„ ๋ฒ„์ „๋ณ„๋กœ ํŽธํ•˜๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.

 

GHCup

 

GHCup

From here you can search these documents. Enter your search terms below.

www.haskell.org

 

curl --proto '=https' --tlsv1.2 -sSf <https://get-ghcup.haskell.org> | sh

 

์„ค์น˜๊ฐ€ ๋๋‚˜๋ฉด, ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ˜„์žฌ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ํˆด ๋ฒ„์ „๋“ค์„

ํ•œ๋ˆˆ์— ํ™•์ธํ•˜๋ฉฐ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

$ ghcup tui

 

 

vscode ๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ Haskell ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

 

๐Ÿ“Œ ์ฒซ๋ฒˆ์งธ Haskell ํ”„๋กœ๊ทธ๋žจ

์ž…๋ฌธ์€ ์—ญ์‹œ Hello World ์ด์ฃ ?

 

// hello.hs

main = putStrLn "Hello World!"

 

์ด์ œ ํ•˜์Šค์ผˆ ํŒŒ์ผ์„ ์ปดํŒŒ์ผํ•ด์ค๋‹ˆ๋‹ค.

 

$ ghc hello.hs

 

์ปดํŒŒ์ผํ•˜๋ฉด hello ์™€ ํ•จ๊ป˜ hello.o ์™€ hello.hi ๋„ ํ•จ๊ป˜ ์ƒ์„ฑ๋˜๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

hello ๋Š” ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํŒŒ์ผ์ด๊ณ  hello.o ๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ ์˜ค๋ธŒ์ ํŠธ ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.

.hi ๋Š” ์˜ค๋ธŒ์ ํŠธํŒŒ์ผ์ด ํ•„์š”๋กœ ํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋‹ด์€ ํŒŒ์ผ๋กœ,

์„œ๋กœ ๋‹ค๋ฅธ ์˜ค๋ธŒ์ ํŠธ ๋ชจ๋“ˆ๋“ค์„ ๋กœ๋“œํ•  ๋•Œ ๋งํฌ ์ •๋ณด๋ฅผ ๋‹ด๊ณ ์žˆ๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.

(C์–ธ์–ด๋กœ ๋”ฐ์ง€๋ฉด .o ๋Š” object ํŒŒ์ผ, .hi ๋Š” .h ํŒŒ์ผ๊ณผ ๋Œ€์‘๋œ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”)

 

$ ./hello

 

ํ˜น์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด runhaskell ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ด๋„ ๋œ๋‹ค.

์š” ์ปค๋ฉ˜๋“œ๋Š” ghc ์„ค์น˜ํ•˜๋ฉด ํ•จ๊ป˜ ๋‚ด์žฅ๋˜์–ด์žˆ๋‹ค.

 

$ runhaskell hello.hs

// Hello World!

 

shell redirection ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด html ํŒŒ์ผ๋กœ output ์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

$ runhaskell hello.hs > hello.html

/**
 * hello.html 
 *
 * <html>
 *  <body>Hello, World!</body>
 * </html>
 */

 

๐Ÿ“Œ ์ฃผ์„

 

Haskell ์—์„œ ์ฃผ์„์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

-- single line comment

ํ˜น์€ 

{- single line comment -}

ํ˜น์€

{-
    multi line comment
-}

 

๐Ÿ“Œ ์ฐธ๊ณ ์ž๋ฃŒ

Learn Haskell by building a blog generator

ํ•˜์Šค์ผˆ "Hello World" ํ”„๋กœ๊ทธ๋žจ

What are the .hi and .o files generated by GHC (on Linux)?

๋ฐ˜์‘ํ˜•

'๐Ÿ“  archive' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Haskell Tutorial] Type  (0) 2022.11.28
[Haskell Tutorial] Function & Chaining  (0) 2022.11.28
[Design Pattern] PUB-SUB ํŒจํ„ด  (0) 2022.06.13
JWT (JSON Web Token)  (0) 2022.05.23
Cookie & Web Storage  (0) 2022.05.22

๐Ÿ’ฌ ๋Œ“๊ธ€