728x90
본격적인 내용에 앞서 사용중인 운영체제에 맞게 아래에서 다운로드하여 설치한다.
https://www.haskell.org/downloads
설치 후 CMD, BASH 또는 WinGHCi, GHCi 에서 ghci 를 실행한다.
1 2 3 | root@gcloudx:~# ghci GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help Prelude> | cs |
표준 프롬프트는 Prelude> 이다. 아래와 같이 프롬프트를 설정할 수도 있다.
1 2 3 4 5 6 7 | root@gcloudx:~# ghci GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help Prelude> :set prompt ">" > > > | cs |
가능한 명령어 목록은 :help 를 통해서 확인할 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | >:help Commands available from the prompt: <statement> evaluate/run <statement> : repeat last command :{\n ..lines.. \n:}\n multiline command :add [*]<module> ... add module(s) to the current target set :browse[!] [[*]<mod>] display the names defined by module <mod> (!: more details; *: all top-level names) :cd <dir> change directory to <dir> :cmd <expr> run the commands returned by <expr>::IO String :complete <dom> [<rng>] <s> list completions for partial input string :ctags[!] [<file>] create tags file for Vi (default: "tags") (!: use regex instead of line number) :def <cmd> <expr> define command :<cmd> (later defined command has precedence, ::<cmd> is always a builtin command) :edit <file> edit file :edit edit last module :etags [<file>] create tags file for Emacs (default: "TAGS") :help, :? display this list of commands :info[!] [<name> ...] display information about the given names (!: do not filter instances) :issafe [<mod>] display safe haskell information of module <mod> :kind[!] <type> show the kind of <type> (!: also print the normalised type) :load [*]<module> ... load module(s) and their dependents :main [<arguments> ...] run the main function with the given arguments :module [+/-] [*]<mod> ... set the context for expression evaluation :quit exit GHCi :reload reload the current module set :run function [<arguments> ...] run the function with the given arguments :script <filename> run the script <filename> :type <expr> show the type of <expr> :undef <cmd> undefine user-defined command :<cmd> :!<command> run the shell command <command> -- Commands for debugging: :abandon at a breakpoint, abandon current computation :back go back in the history (after :trace) :break [<mod>] <l> [<col>] set a breakpoint at the specified location :break <name> set a breakpoint on the specified function :continue resume after a breakpoint :delete <number> delete the specified breakpoint :delete * delete all breakpoints :force <expr> print <expr>, forcing unevaluated parts :forward go forward in the history (after :back) :history [<n>] after :trace, show the execution history :list show the source code around current breakpoint :list <identifier> show the source code for <identifier> :list [<module>] <line> show the source code around line number <line> :print [<name> ...] show a value without forcing its computation :sprint [<name> ...] simplified version of :print :step single-step after stopping at a breakpoint :step <expr> single-step into <expr> :steplocal single-step within the current top-level binding :stepmodule single-step restricted to the current module :trace trace after stopping at a breakpoint :trace <expr> evaluate <expr> with tracing on (see :history) -- Commands for changing settings: :set <option> ... set options :seti <option> ... set options for interactive evaluation only :set args <arg> ... set the arguments returned by System.getArgs :set prog <progname> set the value returned by System.getProgName :set prompt <prompt> set the prompt used in GHCi :set prompt2 <prompt> set the continuation prompt used in GHCi :set editor <cmd> set the command used for :edit :set stop [<n>] <cmd> set the command to run when a breakpoint is hit :unset <option> ... unset options Options for ':set' and ':unset': +m allow multiline commands +r revert top-level expressions after each evaluation +s print timing/memory stats after each evaluation +t print type after evaluation -<flags> most GHC command line flags can also be set here (eg. -v2, -XFlexibleInstances, etc.) for GHCi-specific flags, see User's Guide, Flag reference, Interactive-mode options -- Commands for displaying information: :show bindings show the current bindings made at the prompt :show breaks show the active breakpoints :show context show the breakpoint context :show imports show the current imports :show linker show current linker state :show modules show the currently loaded modules :show packages show the currently active package flags :show paths show the currently active search paths :show language show the currently active language flags :show <setting> show value of <setting>, which is one of [args, prog, prompt, editor, stop] :showi language show language flags for interactive evaluation > | cs |
:set +t 를 통해 타입을 확인할 수 있다.
1 2 3 4 | Prelude> :set +t Prelude> 3 + 4 7 it :: Num a => a | cs |
1 2 3 | Prelude> 2 ^ 777 794889263257962974796277498092801308291525640763748664903194643469338087775424965801409745320266996710649718116931109481559848982586784968419475084821084743272680947722675151641735826243378403750534655587182832000457137589153821622272 it :: Num a => a | cs |
1 2 3 | Prelude> "abc" ++ "xyz" "abcxyz" it :: [Char] | cs |
여기서 "::" 는 "has type" 으로 읽으면 된다.
그리고 표현식의 값은 it라는 이름으로 바운딩된다.
그리고 이 it 는 연속적인 계산에 사용 가능하다.
1 2 3 4 5 6 7 8 9 | Prelude> 3 + 4 7 it :: Num a => a Prelude> it + it * it 56 it :: Num a => a Prelude> it /= it False it :: Bool | cs |
※ GHCi 사용법에 대한 보다 자세한 내용은 아래 링크 참조
https://downloads.haskell.org/~ghc/5.04/docs/html/users_guide/ghci.html
728x90
'프로그래밍 Programming' 카테고리의 다른 글
Functional Programming with Haskell - Calling functions (0) | 2018.03.24 |
---|---|
Functional Programming with Haskell - 패러다임 (0) | 2018.03.24 |
Haskell_007 Where (0) | 2018.03.17 |
Haskell Operators and other Lexical Notation (0) | 2018.03.17 |
Haskell_006 Guards (0) | 2018.03.17 |