redprl / ocaml-bwd Goto Github PK
View Code? Open in Web Editor NEW๐ Backward lists for OCaml
Home Page: https://ocaml.org/p/bwd
License: Apache License 2.0
๐ Backward lists for OCaml
Home Page: https://ocaml.org/p/bwd
License: Apache License 2.0
Previously we decided to deprecate concat
, but it seems useful to collapse 'a bwd bwd
to 'a bwd
when backward lists are used as accumulators.
I wonder why split
was not made tail-recursive while these two functions were? But anyway, it's not difficult to mimic the standard library.
I'm not sure if this is worth it, but I'll document it here anyways. The standard library is currently 2-unrolling a few functions, which means it fuses two recursive calls into one. The main reason is to match the performance, thanks to the careful benchmarking of @nojb. The relevant functions are:
init
map
mapi
map2
I haven't done the unrolling because the potential 20% slow-down on short lists hasn't become a bottleneck yet, but maybe we should do it when more people are using this library.
Naming the submodule Notation
(for infix notations) as Infix
seems to be the convention used in several packages (e.g., containers
). Concretely, the plan is to...
BwdNotation
andBwd.Notation
to Bwd.Infix
and also BwdLabels.Notation
to BwdLabels.Infix
Version 2.1.0 can be released first to deprecate the old modules.
@jonsterling @TOTBWF Thoughts?
Why did you choose an infix notation whose precedence is higher than function application? It's contrary to all my intuitions for f x #< y
to mean f (x #< y)
.
I am curious why the decision was made for Bwd.map
, Bwd.iter
, and so on to operate from right to left rather than from left to right. This is counterintuitive to me (and has led to at least one bug in my code so far). To me, the order in which the elements of a list are visited goes naturally with the textual order, since we read (in English) from left to right.
Moreover, I feel like in practice one of the reasons I care about having things in an order at all is so that I can iterate over them in that order, and the order in which I want to maintain things may be independent from which end of the order I most frequently want to add and remove elements from. In fact I might argue that for adding things, at least, the more common situation is to want to add things at the "end" of the order in which I want to iterate over them.
I'm thinking about adding to_seq
and of_seq
, but there seem to be two possible implementations of to_seq
:
Seq.t
takes O(n) time and then all further items take O(1) time.Seq.t
takes O(1) time but the first item can take O(n) time. Further items take O(1) time.I wonder what would be better? The concern about the second approach is that it can take O(n) time to retrieve the first item every time. One can also memoize it (maybe via lazy
) but I'm not sure if it's worth it.
fold_left_map
in the standard library is tail-recursive.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.