Skip to content

Commit

Permalink
rename binary to string
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Oct 10, 2023
1 parent e767161 commit 667e796
Show file tree
Hide file tree
Showing 39 changed files with 323 additions and 358 deletions.
3 changes: 1 addition & 2 deletions NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ e.g. variables can't be the empty string so no need for a discard or optional ty

- Call All Code program, not code it's made up of a tree. ended up being source. What does unison call it all
- Call parts of it routines. they are named functions that are returened callable as `bin foo args`
- PolyType could like in a type.gleam file and be used under t alias t.Generalised(t.Binary)
- PolyType could like in a type.gleam file and be used under t alias t.Generalised(t.Str)
- write up argument for identity function https://dev.to/rekreanto/why-it-is-impossible-to-write-an-identity-function-in-javascript-and-how-to-do-it-anyway-2j51#section-1

All less important that a cool spreadsheety program
Expand Down Expand Up @@ -302,7 +302,6 @@ Raising is simple design descision

```js
perform("Log")
// fn(Binary) -> <Log Binary | e> Nil

fn log(message) {
perform("Log", message)
Expand Down
2 changes: 1 addition & 1 deletion eyg/saved/saved.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions eyg/src/atelier/app.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fn insert(zipper: zipper.Zipper, state) {
e.Apply(_, _) -> Error("no insert option for apply")
e.Let(var, body, then) -> Ok(write(var, e.Let(_, body, then)))

e.Binary(value) -> Ok(WriteText(value, fn(new) { zipper.1(e.Binary(new)) }))
e.Str(value) -> Ok(WriteText(value, fn(new) { zipper.1(e.Str(new)) }))
e.Integer(value) ->
Ok(WriteNumber(value, fn(new) { zipper.1(e.Integer(new)) }))
e.Tail | e.Cons -> Error("there is no insert for lists")
Expand Down Expand Up @@ -478,9 +478,9 @@ fn variable(zipper: zipper.Zipper, state) {
fn binary(zipper: zipper.Zipper, state) {
let commit = case zipper.0 {
e.Let(label, _value, then) -> fn(text) {
zipper.1(e.Let(label, e.Binary(text), then))
zipper.1(e.Let(label, e.Str(text), then))
}
_exp -> fn(text) { zipper.1(e.Binary(text)) }
_exp -> fn(text) { zipper.1(e.Str(text)) }
}
WorkSpace(..state, mode: WriteText("", commit))
}
Expand All @@ -500,7 +500,7 @@ fn number(zipper: zipper.Zipper, state) {
fn match(zipper: zipper.Zipper, state) {
let commit = case zipper.0 {
// e.Let(label, value, then) -> fn(text) {
// zipper.1(e.Let(label, e.Binary(text), then))
// zipper.1(e.Let(label, e.Str(text), then))
// }
// Match on original value should maybe be the arg? but I like promoting first class everything
exp -> fn(text) {
Expand Down
2 changes: 1 addition & 1 deletion eyg/src/atelier/view/projection.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn do_render(exp, br, loc, inferred) {
e.Apply(func, arg) -> call(func, arg, br, loc, inferred)
e.Let(label, value, then) ->
assigment(label, value, then, br, loc, inferred)
e.Binary(value) -> [string(value, loc, inferred)]
e.Str(value) -> [string(value, loc, inferred)]
e.Integer(value) -> [integer(value, loc, inferred)]
e.Tail -> [
span(
Expand Down
4 changes: 2 additions & 2 deletions eyg/src/atelier/view/typ.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn render_type(typ) {
case typ {
t.Unbound(i) -> int.to_string(i)
t.Integer -> "Integer"
t.Binary -> "Binary"
t.Str -> "String"
t.LinkedList(el) -> string.concat(["List(", render_type(el), ")"])
t.Fun(from, effects, to) ->
string.concat([
Expand Down Expand Up @@ -104,7 +104,7 @@ fn collect_effect(eff, acc) {
fn do_used_in_type(used, type_) {
case type_ {
t.Unbound(i) -> set.insert(used, i)
t.Integer | t.Binary -> used
t.Integer | t.Str -> used
t.LinkedList(el) -> do_used_in_type(used, el)
t.Fun(arg, effect, ret) ->
used
Expand Down
12 changes: 6 additions & 6 deletions eyg/src/easel/embed.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ pub fn insert_text(state: Embed, data, start, end) {

e.Vacant(_) ->
case data {
"\"" -> #(e.Binary(""), [], 0, False)
"\"" -> #(e.Str(""), [], 0, False)
"[" -> #(e.Tail, [], 0, False)
"{" -> #(e.Empty, [], 0, False)
// TODO need to add path to step in
Expand Down Expand Up @@ -730,9 +730,9 @@ pub fn insert_text(state: Embed, data, start, end) {
}
}
}
e.Binary(value) -> {
e.Str(value) -> {
let value = stringx.replace_at(value, cut_start, cut_end, data)
#(e.Binary(value), [], cut_start + string.length(data), True)
#(e.Str(value), [], cut_start + string.length(data), True)
}
e.Integer(value) -> {
case data == "-" && cut_start == 0 {
Expand Down Expand Up @@ -1083,7 +1083,7 @@ pub fn perform(state: Embed, start, end) {
pub fn string(state: Embed, start, end) {
use path <- single_focus(state, start, end)
use _target <- update_at(state, path)
#(e.Binary(""), Insert, [])
#(e.Str(""), Insert, [])
}

// shift d for delete line
Expand Down Expand Up @@ -1196,10 +1196,10 @@ pub fn insert_paragraph(index, state: Embed) {
let assert Ok(#(target, rezip)) = zipper.at(source, path)

let #(new, sub, offset) = case target {
e.Binary(content) -> {
e.Str(content) -> {
// needs end for large enter, needs to be insert mode only
let #(content, offset) = replace_at(content, offset, offset, "\n")
#(e.Binary(content), [], offset)
#(e.Str(content), [], offset)
}
e.Let(label, value, then) -> {
#(e.Let(label, value, e.Let("", e.Vacant(""), then)), [1], 0)
Expand Down
4 changes: 2 additions & 2 deletions eyg/src/easel/loader.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn applet(root) {
let id = int.to_string(list.length(saved))
let saved = [action, ..saved]
javascript.set_reference(actions, saved)
r.prim(r.Value(r.Binary(id)), rev, env, k)
r.prim(r.Value(r.Str(id)), rev, env, k)
},
)
|> map.insert("Log", console_log().2)
Expand All @@ -77,7 +77,7 @@ fn applet(root) {
let current = javascript.dereference(state)
let result = r.handle(r.eval_call(func, current, env, None), handlers)
let _ = case result {
r.Value(r.Binary(page)) -> document.set_html(root, page)
r.Value(r.Str(page)) -> document.set_html(root, page)
_ -> {
io.debug(#("unexpected", result))
panic("nope")
Expand Down
2 changes: 1 addition & 1 deletion eyg/src/easel/print.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn do_print(source, loc: Location, br, acc, info, analysis) {
info,
analysis,
)
e.Binary(value) -> {
e.Str(value) -> {
let acc = [#("\"", loc.path, -1, String, err), ..acc]
// Maybe I don't need to append " if looking left
// Dont escape html here as messes up index's when looking up element
Expand Down
2 changes: 1 addition & 1 deletion eyg/src/eyg/analysis/inference.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn do_infer(env, exp, typ, eff, ref, path) {
|> compose(unify(typ, typ, ref, path))
}
// Primitive
e.Binary(_) -> unify(typ, t.Binary, ref, path)
e.Str(_) -> unify(typ, t.Str, ref, path)
e.Integer(_) -> unify(typ, t.Integer, ref, path)
e.Tail -> unify(typ, t.tail(ref), ref, path)
e.Cons -> unify(typ, t.cons(ref), ref, path)
Expand Down
2 changes: 1 addition & 1 deletion eyg/src/eyg/analysis/jm/tree.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn primitive(exp, next) {
| e.Lambda(_, _)
| e.Let(_, _, _)
| e.Builtin(_) -> panic("not a literal")
e.Binary(_) -> #(t.String, next)
e.Str(_) -> #(t.String, next)
e.Integer(_) -> #(t.Integer, next)

e.Tail -> t.tail(next)
Expand Down
2 changes: 1 addition & 1 deletion eyg/src/eyg/analysis/substitutions.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn apply(sub: Substitutions, typ) {
t.Fun(apply(sub, from), apply_effects(sub, effects), apply(sub, to))
t.Record(row) -> t.Record(apply_row(sub, row))
t.Union(row) -> t.Union(apply_row(sub, row))
t.Integer | t.Binary -> typ
t.Integer | t.Str -> typ
t.LinkedList(element) -> t.LinkedList(apply(sub, element))
}
}
Expand Down
4 changes: 2 additions & 2 deletions eyg/src/eyg/analysis/typ.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub type Row(kind) {
pub type Term {
Unbound(Int)
Integer
Binary
Str
LinkedList(Term)
Fun(Term, Row(#(Term, Term)), Term)
// Row parameterised by T for effects
Expand All @@ -30,7 +30,7 @@ pub type Variable {
pub fn ftv(typ) {
case typ {
Unbound(x) -> setx.singleton(Term(x))
Integer | Binary -> set.new()
Integer | Str -> set.new()
LinkedList(element) -> ftv(element)
Record(row) -> ftv_row(row)
Union(row) -> ftv_row(row)
Expand Down
4 changes: 2 additions & 2 deletions eyg/src/eyg/analysis/unification.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn unify(t1, t2, ref) -> Result(_, _) {
Ok(sub.compose(s4, s3))
}
t.Unbound(u), t | t, t.Unbound(u) -> varbind(u, t)
t.Binary, t.Binary -> Ok(sub.none())
t.Str, t.Str -> Ok(sub.none())
t.Integer, t.Integer -> Ok(sub.none())
t.LinkedList(i1), t.LinkedList(i2) -> unify(i1, i2, ref)
t.Record(r1), t.Record(r2) -> unify_row(r1, r2, ref)
Expand Down Expand Up @@ -167,7 +167,7 @@ pub fn resolve(s, typ) {
t.Unbound(a) ->
map.get(terms, a)
|> result.unwrap(typ)
t.Binary | t.Integer -> typ
t.Str | t.Integer -> typ
t.LinkedList(element) -> t.LinkedList(resolve(s, element))
t.Fun(t, e, u) -> t.Fun(resolve(s, t), resolve_effect(s, e), resolve(s, u))
t.Record(r) -> t.Record(resolve_row(s, r))
Expand Down
4 changes: 2 additions & 2 deletions eyg/src/eyg/runtime/capture.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn capture(term) {
fn do_capture(term, env) {
case term {
r.Integer(value) -> #(e.Integer(value), env)
r.Binary(value) -> #(e.Binary(value), env)
r.Str(value) -> #(e.Str(value), env)
r.LinkedList(items) ->
list.fold_right(
items,
Expand Down Expand Up @@ -76,7 +76,7 @@ fn do_capture(term, env) {
// could special rule std by passing in as an argument
//
let #(exp, env) = case var {
// "std" -> #(e.Binary("I AM STD"), env)
// "std" -> #(e.Str("I AM STD"), env)
_ -> do_capture(term, env)
}
case list.key_find(env, var) {
Expand Down
6 changes: 3 additions & 3 deletions eyg/src/eyg/runtime/interpreter.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn handle(return, extrinsic) {

pub type Term {
Integer(value: Int)
Binary(value: String)
Str(value: String)
LinkedList(elements: List(Term))
Record(fields: List(#(String, Term)))
Tagged(label: String, value: Term)
Expand Down Expand Up @@ -165,7 +165,7 @@ pub fn error(reason) {
pub fn to_string(term) {
case term {
Integer(value) -> int.to_string(value)
Binary(value) -> string.concat(["\"", value, "\""])
Str(value) -> string.concat(["\"", value, "\""])
LinkedList(items) ->
list.map(items, to_string)
|> list.intersperse(", ")
Expand Down Expand Up @@ -400,7 +400,7 @@ fn step(exp, rev, env: Env, k) {
}

E(e.Integer(value)) -> K(V(Value(Integer(value))), rev, env, k)
E(e.Binary(value)) -> K(V(Value(Binary(value))), rev, env, k)
E(e.Str(value)) -> K(V(Value(Str(value))), rev, env, k)
E(e.Tail) -> K(V(Value(LinkedList([]))), rev, env, k)
E(e.Cons) -> K(V(Value(Defunc(Cons, []))), rev, env, k)
E(e.Vacant(comment)) ->
Expand Down
24 changes: 12 additions & 12 deletions eyg/src/eyg/runtime/standard.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ pub fn web() {
t.Fun(
t.Record(t.Extend(
"method",
t.Binary,
t.Str,
t.Extend(
"scheme",
t.Binary,
t.Str,
t.Extend(
"host",
t.Binary,
t.Str,
t.Extend(
"path",
t.Binary,
t.Extend("query", t.Binary, t.Extend("body", t.Binary, t.Closed)),
t.Str,
t.Extend("query", t.Str, t.Extend("body", t.Str, t.Closed)),
),
),
),
)),
t.Extend(
"Log",
#(t.Binary, t.Record(t.Closed)),
#(t.Str, t.Record(t.Closed)),
t.Extend(
"HTTP",
#(
Expand All @@ -35,21 +35,21 @@ pub fn web() {
t.Union(t.Extend("HTTPS", t.unit, t.Closed)),
t.Extend(
"host",
t.Binary,
t.Str,
t.Extend(
"port",
t.option(t.Integer),
t.Extend(
"path",
t.Binary,
t.Str,
t.Extend(
"query",
t.option(t.Binary),
t.option(t.Str),
t.Extend(
"headers",
// I don't have tuples for a list of headers so this is not yet implemented
t.LinkedList(t.Binary),
t.Extend("body", t.Binary, t.Closed),
t.LinkedList(t.Str),
t.Extend("body", t.Str, t.Closed),
),
),
),
Expand All @@ -67,7 +67,7 @@ pub fn web() {
),
),
),
t.Record(t.Extend("body", t.Binary, t.Closed)),
t.Record(t.Extend("body", t.Str, t.Closed)),
)
}

Expand Down
2 changes: 1 addition & 1 deletion eyg/src/eygir/decode.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn decoder(x) {
"i" | "integer" ->
decode1(e.Integer, any([field("value", int), field("v", int)]))
"s" | "binary" ->
decode1(e.Binary, any([field("value", string), field("v", string)]))
decode1(e.Str, any([field("value", string), field("v", string)]))
"ta" | "tail" -> fn(_) { Ok(e.Tail) }
"c" | "cons" -> fn(_) { Ok(e.Cons) }
"z" | "vacant" ->
Expand Down
2 changes: 1 addition & 1 deletion eyg/src/eygir/encode.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn encode(exp) {
|> node("l", _)
e.Integer(i) -> node("i", [#("v", int(i))])
// string
e.Binary(s) -> node("s", [#("v", string(s))])
e.Str(s) -> node("s", [#("v", string(s))])
e.Tail -> node("ta", [])
e.Cons -> node("c", [])
// zero
Expand Down
2 changes: 1 addition & 1 deletion eyg/src/eygir/expression.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub type Expression {

// Primitive
Integer(value: Int)
Binary(value: String)
Str(value: String)

Tail
// type system won't allow improper list
Expand Down
Loading

0 comments on commit 667e796

Please sign in to comment.