Implement echo example

This commit is contained in:
Richard Feldman 2021-08-21 21:50:55 -04:00
parent 6b6c439d6a
commit 368ced972d
7 changed files with 31 additions and 18 deletions

View File

@ -1 +1 @@
cli-example
echo

18
examples/cli/Echo.roc Normal file
View 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)!"

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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 {})

View File

@ -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;