-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyApp.elm
39 lines (29 loc) · 785 Bytes
/
MyApp.elm
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
module MyApp exposing (..)
import IO exposing (IO)
import Cli exposing (CliProgram)
main : CliProgram
main =
Cli.run program
program : IO ()
program =
IO.do (askName) <| \name ->
IO.do (IO.writeLine <| "Hello " ++ name) <| \_ ->
IO.do (askAge) <| \age ->
if age > 18 then
IO.writeLine "You are an adult"
else
IO.writeLine "You are minor..."
askName : IO String
askName =
IO.do (IO.writeLine "What's your name?") <| \_ ->
IO.readLine
askAge : IO Float
askAge =
IO.do (IO.writeLine "What's your age?") <| \_ ->
IO.do (IO.readLine) <| \age ->
case String.toFloat age of
Just f ->
IO.return f
Nothing ->
IO.do (IO.writeLine "Not a number, try again") <| \_ ->
askAge