mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-13 09:49:11 +03:00
Implement echo example
This commit is contained in:
parent
6b6c439d6a
commit
368ced972d
2
examples/cli/.gitignore
vendored
2
examples/cli/.gitignore
vendored
@ -1 +1 @@
|
||||
cli-example
|
||||
echo
|
||||
|
18
examples/cli/Echo.roc
Normal file
18
examples/cli/Echo.roc
Normal file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env roc
|
||||
|
||||
app "echo"
|
||||
packages { base: "platform" }
|
||||
imports [ base.Task.{ Task, await }, base.Stdout, base.Stdin ]
|
||||
provides [ main ] to base
|
||||
|
||||
main : Task {} *
|
||||
main =
|
||||
{} <- await (Stdout.line "What's your first name?")
|
||||
|
||||
firstName <- await Stdin.line
|
||||
|
||||
{} <- await (Stdout.line "What's your last name?")
|
||||
|
||||
lastName <- await Stdin.line
|
||||
|
||||
Stdout.line "Hi, \(firstName) \(lastName)!"
|
@ -1,8 +0,0 @@
|
||||
app "cli-example"
|
||||
packages { base: "platform" }
|
||||
imports [ fx.Effect ]
|
||||
provides [ main ] to base
|
||||
|
||||
main : Effect.Effect {}
|
||||
main =
|
||||
Effect.after Effect.getLine \lineThisThing -> Effect.putLine lineThisThing
|
4
examples/cli/platform/Cargo.lock
generated
4
examples/cli/platform/Cargo.lock
generated
@ -12,9 +12,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.92"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714"
|
||||
checksum = "a1fa8cddc8fbbee11227ef194b5317ed014b8acbf15139bd716a18ad3fe99ec5"
|
||||
|
||||
[[package]]
|
||||
name = "roc_std"
|
||||
|
@ -1,8 +1,8 @@
|
||||
platform examples/cli
|
||||
requires {} { main : Effect {} }
|
||||
requires {}{ main : Task {} [] } # TODO FIXME
|
||||
exposes []
|
||||
packages {}
|
||||
imports [ fx.Effect ]
|
||||
imports [ Task.{ Task } ]
|
||||
provides [ mainForHost ]
|
||||
effects fx.Effect
|
||||
{
|
||||
@ -10,6 +10,5 @@ platform examples/cli
|
||||
getLine : Effect Str
|
||||
}
|
||||
|
||||
|
||||
mainForHost : Effect.Effect {} as Fx
|
||||
mainForHost : Task {} [] as Fx
|
||||
mainForHost = main
|
||||
|
@ -1,6 +1,9 @@
|
||||
interface Stdout
|
||||
exposes [ line ]
|
||||
imports [ fx.Effect, Task ]
|
||||
imports [ fx.Effect, Task.{ Task } ]
|
||||
|
||||
line : Str -> Task.Task {} *
|
||||
line = \line -> Effect.map (Effect.putLine line) (\_ -> Ok {})
|
||||
# line : Str -> Task.Task {} *
|
||||
# line = \line -> Effect.map (Effect.putLine line) (\_ -> Ok {})
|
||||
|
||||
line : Str -> Task {} *
|
||||
line = \str -> Effect.map (Effect.putLine str) (\_ -> Ok {})
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::alloc::Layout;
|
||||
use core::ffi::c_void;
|
||||
use core::mem::MaybeUninit;
|
||||
use libc;
|
||||
use roc_std::{RocCallResult, RocStr};
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw::c_char;
|
||||
|
Loading…
Reference in New Issue
Block a user