갈루아의 반서재

다음과 같이 함수를 정의할 때 parse error 가 나는 것은 ghci 버전 차이에 따른 것이다. GHCi 가 7.x 또는 그 미만인 경우에는 let 을 통해 함수를 정의해야 한다. 

  1. Prelude> boomBangs xs = [if x < 10 then "BOOM!" else "BANG!" | x <- xs, odd x]
  2.  
  3. <interactive>:74:14: parse error on input ‘=

그러면 현재 사용중인 ghci 버전은 어떻게 확인할 수 있을까. 다음과 같이 확인가능하다. 버전이 7.10.3 이다.

1
2
(blackbriar) root@gcloudx:~/blackbriar/blackbriar/lab/miran# ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.3
cs

그런데 스택의 버전과 상이하다. 에러가 발생한 것은 stack ghci 가 아닌 ghci 로 로딩을 하여 7.x 버전이 실행되었기 때문이다.

1
2
(blackbriar) root@gcloudx:~/blackbriar/blackbriar/lab/miran# stack ghc -- --version
The Glorious Glasgow Haskell Compilation System, version 8.0.2
cs

/root/blackbriar/blackbriar/stack.yaml 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/
 
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
#  name: custom-snapshot
#  location: "./custom-snapshot.yaml"
resolver: lts-9.14
cs

plain GHCi로 실행하면 다음과 같이 깔끔하게 작동한다.

1
2
3
4
5
(blackbriar) root@gcloudx:~/blackbriar/blackbriar/lab/miran# stack exec ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Prelude> boomBangs xs = [ if x < 10 then "BOOM!" else "BANG!" | x <- xs, odd x]
Prelude> boomBangs [7..13]
["BOOM!","BOOM!","BANG!","BANG!"]
cs


How do I determine my ghc version?

https://stackoverflow.com/questions/13073792/how-do-i-determine-my-ghc-version


Running plain ghci

https://docs.haskellstack.org/en/stable/ghci/#running-plain-ghci