개발이야기
osx에 haskell 설치
준호씨
2016. 5. 4. 08:26
반응형
나프다 듣다가 haskell 설치 해 보기로 함. 예전에도 설치 했던 거 같긴 한데... 그리고 haskell 의 미국식 발음은 해스컬이라고 함. 한국이나 일본은 하스켈이라고 발음하고 있음.
여기 가서 다운 받아서 설치 한다.
예전 버전 삭제. 이번에 설치 된 건 7.10.3
$ sudo uninstall-hs only 7.10.2 --remove
-- Removing just version 7.10.2
예전엔 뭐하느라 설치 했던 걸까
설치가 되면 file:///Library/Haskell/doc/start.html 페이지가 뜸
7.10.2 를 지웠고 7.10.3 이 선택 되어 있음.
$ sudo activate-hs
Haskell now set to:
GHC 7.10.3
Arch. x86_64
Platform 7.10.3
View documentation with this command:
open /Library/Haskell/doc/start.html
https://wiki.haskell.org/Haskell_in_5_steps 처음엔 요 문서가 좋은 듯
설치 하기 귀찮으면 http://tryhaskell.org/ 에서 실습 해 볼 수 있군. 그런데 좀 느리다.
터미널에서 간단히 실습 해 보자
ghci 를 실행하면 커맨드 라인환경에서 haskell 을 이용 해 볼 수 있다. REPL~ 이것 저것 막막 해 보자. tab 누르면 관련 함수들도 나옴.
$ ghci
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
Prelude> reverse "hello"
"olleh"
Prelude> 11 * 11
121
Prelude> foldr (:) [] [1,2,3]
[1,2,3]
Prelude> do line <- getLine; putStr
putStr putStrLn
Prelude> do line <- getLine; putStrLn line
haha
haha
Prelude> readFile "/welcome"
*** Exception: /welcome: openFile: does not exist (No such file or directory)
Prelude> readFile "test.txt"
"hello world\n"
haskell 소스 파일의 확장자는 hs 이다.
hello.hs
main = putStrLn "Hello, World!"
파일을 만들고 컴파일 할 수 있다. (그런데 hello world 용량이 1.3M)
$ ghc -o hello hello.hs
$ ./hello
Hello, World!
컴파일 안하고 그냥 실행 할 수도 있다.
$ runhaskell hello.hs
Hello, World!
반응형