git.iko.soy/lynxjs-elm/compiler
on master help sign in
73 lines 1.5 kB history raw
2# REPL
4The REPL lets you interact with Elm values and functions in your terminal.
7## Use
9You can type in expressions, definitions, custom types, and module imports using normal Elm syntax.
11```elm
12> 1 + 1
132 : number
15> "hello" ++ "world"
16"helloworld" : String
17```
19The same can be done with definitions and custom types:
21```elm
22> fortyTwo = 42
2342 : number
25> increment n = n + 1
26<function> : number -> number
28> increment 41
2942 : number
31> factorial n =
32| if n < 1 then
33| 1
34| else
35| n * factorial (n-1)
37<function> : number -> number
39> factorial 5
40120 : number
42> type User
43| = Regular String
44| | Visitor String
47> case Regular "Tom" of
48| Regular name -> "Hey again!"
49| Visitor name -> "Nice to meet you!"
51"Hey again!" : String
52```
54When you run `elm repl` in a project with an [`elm.json`](https://github.com/elm/compiler/blob/master/docs/elm.json/application.md) file, you can import any module available in the project. So if your project has an `elm/html` dependency, you could say:
56```elm
57> import Html exposing (Html)
59> Html.text "hello"
60<internals> : Html msg
62> Html.text
63<function> : String -> Html msg
64```
66If you create a module in your project named `MyThing` in your project, you can say `import MyThing` in the REPL as well. Any module that is accessible in your project should be accessible in the REPL.
69## Exit
71To exit the REPL, you can type `:exit`.
73You can also press `ctrl-d` or `ctrl-c` on some platforms.