Comments (3)
Here's a list of bind functions before and after this proposed change.
Basically, whenever we apply something to nxt
we swap that for applying to (args nxt)
, although that might not be exactly the case for all bind functions.
type Maybe = (Some val) | None
type Result = (Ok val) | (Err val)
Maybe/bind = @val @nxt match val {
Maybe/Some: (nxt val.val)
Maybe/None: None
}
Maybe/bind_ = @args @val @nxt match val {
Maybe/Some: (args nxt val.val)
Maybe/None: None
}
Result/bind = @val @nxt match val {
Result/Ok: (nxt val.val)
Result/Err: (Result/Err val.val)
}
Result/bind_ = @args @val @nxt match val {
Result/Ok: (args nxt val.val)
Result/Err: (Result/Err val.val)
}
List/concat (List/Cons x xs) ys = (List/Cons x (List/concat xs ys))
List/concat List/Nil ys = ys
List/flatten List/Nil = List/Nil
List/flatten (List/Cons x xs) = (List/concat x (List/flatten xs))
List/map (List/Cons x xs) f = (List/cons (f x) (List/map xs f))
List/map List/Nil f = List/Nil
List/bind = @val @nxt match val {
List/Cons: (List/flatten (List/map val nxt))
List/Nil: None
}
List/bind_ = @args @val @nxt match val {
List/Cons: (List/flatten (List/map val (args nxt)))
List/Nil: None
}
State/bind = @val @nxt @state let (state, res) = (val state); (nxt res state)
State/bind_ = @args @val @nxt @state let (state, res) = (val state); (args nxt res state)
Identity/bind = @val @nxt (nxt val)
Identity/bind_ = @args @val @nxt (args nxt val)
Continuation/bind = @val @nxt @cont (val (@a (nxt a cont)))
Continuation/bind_ = @args @val @nxt @cont (val (@a (args nxt a cont)))
IO/bind_ = @args @val @nxt match val {
IO/Done: ((args nxt) val.expr)
IO/Call: (IO/Call IO/MAGIC val.func val.argm @x (IO/bind_ args (val.cont x) nxt))
}
from bend.
A suggestion by @tjjfvi on discord:
another approach that I believe would solve this:
I'm going to use defer value as shorthand for @unit match unit with * { Unit: value }
, and undefer value as shorthand for (value unit), where
data Unit = Unit // desugars to Unit = @x x
; idk what new bend syntax is for this
a <- Val
nxt(a, free1,..., freen)
# desugars to
(bind Val (defer @a (nxt a free1 ... freen)))
# which itself desugars to
(bind Val @id (id @free1 ... @freen @a (nxt a free1 ... freen) free1 ... freen))
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# combinator!
# bind changes from
Maybe/bind = @val @nxt match val {
Maybe/Some: (nxt val.val)
Maybe/None: None
}
# to
Maybe/bind_ = @val @nxt match val {
Maybe/Some: ((undefer nxt) val.val)
Maybe/None: None
}
# which desugars to
Maybe/bind_ = @val @nxt match val {
Maybe/Some: (nxt Unit val.val)
Maybe/None: None
}
defer is the inet equivalent of a lazy thunk
from bend.
A short example where this is necessary
type Result = (Ok val) | (Err val)
Result/bind = @val @nxt match val {
Result/Ok: ((undefer nxt) val.val)
Result/Err: (Result/Err val.val)
}
Result/foo x y =
with Result {
ask a = (Result/Ok x)
ask b = switch y { 0: (Result/Err a); _: (Result/Ok y-1) }
(Result/foo a b)
}
main = (Result/foo 1 2)
from bend.
Related Issues (20)
- Bend Package Manager: MVS Integration
- Implement type system for Bend HOT 2
- Fix IO/FS/read_line EOF Handling Issue HOT 2
- Define Versioning Requirements
- Design the Versioning Logic
- Implement MVS in BPM
- Testing and Validation of package manager
- Add IO functions for removing files and directories
- Add IO function for copying files and directories
- File copying
- Add IO functions for moving files and directories
- Add IO function for calling subprocesses
- Add all compiler options to documentation
- Outdated `run` commands in GUIDE.md
- Document single-line and multi-line commenting for Bend users HOT 1
- Document existing IO functionalities
- Implement List/sum and List/range functions in Bend built-ins
- `IO/done_on_err` doesn't work with `IO/bind` HOT 1
- `IO/done_on_err` doesn't work with `IO/bind` HOT 2
- String/decode_utf8 returns "\0" when decoding a empty List
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bend.