[Caml-list] Attn: Development Editor, Latest OCaml Weekly News

Alan Schmitt
2020-05-12T07:45:39Z

[-- Attachment #1: Type: text/plain, Size: 15797 bytes --]

Hello

Here is the latest OCaml Weekly News, for the week of May 05 to 12,
2020.

Table of Contents
─────────────────

Looking for "lovely, idiomatic" examples of Ocaml used for shell-scripting in the manner of Perl/Python (but esp. Perl)
Are there learning materials for OCaml for those with no programming experience?
Dune meeting notes
OCaml 4.11.0, first alpha release
OCaml Users and Developers Meeting 2020
VSCode Platform Plugin 0.5.0
Other OCaml News
Old CWN

Looking for "lovely, idiomatic" examples of Ocaml used for shell-scripting in the manner of Perl/Python (but esp. Perl)
═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════

Archive:
[https://discuss.ocaml.org/t/looking-for-lovely-idiomatic-examples-of-ocaml-used-for-shell-scripting-in-the-manner-of-perl-python-but-esp-perl/5703/13]

Continuing this thread, Chet Murthy said and Aaron L. Zeng replied
──────────────────────────────────────────────────────────────────

• needs to be Ocaml code, not an interpreter. I mean, if
I’m not going to write it in Ocaml, I might as well
write in Perl, yes?

I think shexp might deserve another look. It's not an interpreter for
a sexp-based shell language, as its name might unfortunately
deceivingly suggest. It's really a DSL for constructing shell
pipelines using a `'a Process.t' monad. The s-expression part is
advertising that you can debug and trace the actions performed using
s-expressions.

The second-most-important part of Perl/Bash scripting is
string-handling. And it’s certainly the part of Ocaml
that’s most painful when writing scripts. Let’s stipulate
that there are nice libraries to make this easy. I’m an
Ocaml bigot, I have to believe this anyway *grin* . This
library doesn’t seem to use 'em, nor choose/promote a
particular set of such libraries.

I've found [Base] plus [Re] to be sufficient for most of my
string-manipulation needs. It's never going to be as concise as
Perl's built-in "magic" support for regexps, but you gain explicitness
and clarity, which is part of the benefit of OCaml anyway.

[Base] https://github.com/janestreet/base/

[Re] https://github.com/ocaml/ocaml-re

Chet Murthy said and Donn Cave replied
──────────────────────────────────────

It’s not as trivial in Ocaml, for many complicated reasons
that boil down to “gee, string-handling is a PITA”.

Really? hadn't noticed. Ha ha.

I could never really get urge for Perl, but I use its ancestor awk a
lot, and I'm trying out some awk-like simple string functions, like

┌────
│ let strlen = String.length
│ let sub s i n = let b = strlen s
│ in if i < b
│ then let n = min n (b - i)
│ in String.sub s i n
│ else ""
│ (* substring to end of line *)
│ let substr a i = if i < strlen a
│ then String.sub a i ((strlen a) - i)
│ else ""
│ let matchre t s = try
│ Str.search_forward t s 0
│ with | Not_found -> -1
└────

etc.

So "open Awk" gets me a handful of more basic variations on common
string functions, with less elaborate parameters, no normal
exceptions, etc. Including a line by line file processing function.
I have just newly started on this and haven't used it extensively, but
it seems fairly promising. No wacky syntax or hyper intelligent
string processing, no packages, just a few dozen lines of cheater
functions.

"Awk" is a misnomer, in that there's little correspondence between
this and awk, it was just what inspired me to try it.

Raphaël Proust said
───────────────────

I don't think it's lovely and I have no idea if it is idiomatic, but I
made a few scripts of my own in OCaml using the same library that
other mentioned: `bos'

• [typepass] uses `xdotool' to type passwords from the `password'
password manager
• [conn] wraps `wpa_supplicant', `dhcpcd', `ip', and other network
management CLI
• [laptop-status] fetches status information for laptops (e.g.,
battery level) and prints it in a nicely formatted form
• [bakelite] increases or decreases screen brightness

[typepass] https://gitlab.com/raphael-proust/typepass

[conn] https://gitlab.com/raphael-proust/conn

[laptop-status] https://gitlab.com/raphael-proust/laptop-status

[bakelite] https://gitlab.com/raphael-proust/bakelite

Vasile Rotaru also said
───────────────────────

[https://github.com/hammerlab/genspio]

Gabriel Radanne also said
─────────────────────────

I have no particular opinion about the rest, but at least on the regex
side, this might be of interest:
[https://github.com/paurkedal/ppx_regexp]

If that's still not good enough, I would be very interested by
suggestions on how to make it more convenient. :)

OCamlUser proposed
──────────────────

I'm not sure about idiomatic, but I do have a utop config that I use
to do some one-off scripting in OCaml that uses `shexp'

┌────
│ #use "topfind"
│ #warnings "+a"
│ #thread
│ #require "ppx_jane,core"
│ #require "shexp.process"
│ #require "lambdasoup"
│ module List' = List
│ open Shexp_process
│ open Shexp_process.Infix
│ open Core
│
│ module Html = struct
│ include Soup
│
│ let of_string = parse
│ end
│
│ let read_lines cmd =
│ eval (call cmd |- read_all)
│ ;;
│
│ let wget url =
│ read_lines ["wget"; "-O"; "-"; url]
│ ;;
│
│ let chrome_curl url =
│ read_lines ["curl"; "-k"; "-sA"; "Chrome"; "-L"; url; "-o"; "-"]
│ ;;
│
│ let split_lines = String.split ~on:'\n'
│ let filter_lines substring = List.filter ~f:String.(is_substring ~substring)
│ let to_html = Html.of_string
│ let find_html pat html = Html.(html $$ pat)
│
│ let (%) = Fn.compose
└────

Then a simple script called `shexp' in my path:
┌────
│ utop -init ~/bin/ocaml-shexp-config
└────

I add little helper functions as I come upon them. I find it's much
easier to transition to a file, or full program when I need
it. Example program:

┌────
│ utop # read_lines ["sensors"] |> split_lines |> filter_lines "Core 0";;
│ - : string list =
│ ["Core 0: +63.0°C (high = +84.0°C, crit = +100.0°C)"]
└────

Anton Kochkov said
──────────────────

Not exactly OCaml, but can be made with the OCaml syntax as well - see
[BATSH].

[BATSH] https://github.com/batsh-dev-team/Batsh

Bikal Lem also said
───────────────────

I just found this - [https://github.com/ShamoX/cash]. @Chet_Murthy
This may be the closest to ocaml shell scripting experience re perl.

Are there learning materials for OCaml for those with no programming experience?
════════════════════════════════════════════════════════════════════════════════

Archive:
[https://discuss.ocaml.org/t/are-there-learning-materials-for-ocaml-for-those-with-no-programming-experience/5684/9]

Continuing this threaad, Luc_ML said
────────────────────────────────────

Before studying more complex books, it's a good idea to first get an
overview.

[OCaml for the Skeptical / OCaml in a Nutshell] : the title is funny;
its main advantage is that it covers most OCaml concepts in *21 short
sections* where you can experiment by yourself on simple but essential
things.

The books/courses already mentioned are nice. You can also consider
this one that offers many examples/exercises and also a good overview:
[Developing Applications With Objective Caml].

LE LANGAGE CAML mentioned by @nojb is an excellent book. Written in
Caml Light, it's easy to turn it by yourself into OCaml. It offers a
great chance to learn how to do a lot of things in *pure* Caml with
only stdlib and a simple syntax extension system (use camlp5 (i.e. the
"genuine camlp4") that is fine for that. It works out of the box to
deal with streams and it's a chance to understand what is a
LL(1)/recursive descent parser).

[OCaml for the Skeptical / OCaml in a Nutshell]
https://www2.lib.uchicago.edu/keith/ocaml-class/class-01.html

[Developing Applications With Objective Caml]
https://caml.inria.fr/pub/docs/oreilly-book/

Dune meeting notes
══════════════════

Archive: [https://discuss.ocaml.org/t/dune-meeting-notes/5710/1]

Jérémie Dimino announced
────────────────────────

I just wanted to publicise that we are now publishing the notes from
our Dune meetings on the wiki:

[https://github.com/ocaml/dune/wiki]

These meetings happen via video-conference every two weeks. If you are
interested in following the development of Dune more closely, this is
good place to look at.

OCaml 4.11.0, first alpha release
═════════════════════════════════

Archive:
[https://discuss.ocaml.org/t/ocaml-4-11-0-first-alpha-release/5716/1]

octachron announced
───────────────────

The set of new features for the future version 4.11.0 of OCaml has
been frozen. In the next few months, the OCaml compiler team is
focusing on bug hunting and fixing.

For this release cycle, we have decided to test publishing regularly
alpha versions of OCaml 4.11.0 in order to help fellow hackers join us
early in our bug hunting and opam ecosystem fixing fun. Once the opam
ecosystem is in shape, these alpha releases will morph into the usual
beta and release candidate releases.

If you find any bugs, please report them here:
[https://github.com/ocaml/ocaml/issues]

The compiler can be installed as an OPAM switch with one of the
following commands
┌────
│ opam switch create ocaml-variants.4.11.0+alpha1 --repositories=default,beta=git+https://github.com/ocaml/ocaml-beta-repository.git
└────
or
┌────
│ opam switch create ocaml-variants.4.11.0+alpha1+VARIANT --repositories=default,beta=git+https://github.com/ocaml/ocaml-beta-repository.git
└────
where you replace VARIANT with one of these: afl, flambda, fp,
fp+flambda

The source code for the alpha is also available at these addresses:

[https://github.com/ocaml/ocaml/archive/4.11.0+alpha1.tar.gz]
[https://caml.inria.fr/pub/distrib/ocaml-4.11/ocaml-4.11.0+alpha1.tar.gz]

If you are interested by the ongoing list of new features and fixed
bugs, the updated change log for OCaml 4.11.0 is available at:

[https://github.com/ocaml/ocaml/blob/4.11/Changes]

OCaml Users and Developers Meeting 2020
═══════════════════════════════════════

Archive:
[https://discuss.ocaml.org/t/ocaml-users-and-developers-meeting-2020/5454/2]

Ivan Gotovchits announced
─────────────────────────

Due to the multiple requests and since ICFP will be now officially
held online with a significantly reduced fee, we decided to extend the
submission deadline till the end of this month. We are hoping to
attract a larger and more diverse audience this year, given that the
new format is more accessible both travel-wise and financially.

Please, share the news widely!

Important Dates (updated)
╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌

• Talk proposal submission deadline: May 29th, 2020, AoE
• Author Notification: July 17th, 2020
• OCaml Workshop: August 28th, 2020

VSCode Platform Plugin 0.5.0
════════════════════════════

Archive:
[https://discuss.ocaml.org/t/ann-vscode-platform-plugin-0-5-0/5752/1]

Rudi Grinberg announced
───────────────────────

This release contains a couple of major improvements:

• Syntax highlighting is vastly improved. There's now highlighting for
many more filetypes, and the core highlighting for OCaml is far more
accurate.
• There's integration with package managers such as opam and esy. One
may now explicitly use them to explicitly select the sandbox that
contains the lsp server and related tools.

Under the hood, the entire plugin was rewritten from typescript to
OCaml (bucklescript). This should hopefully make contribution more
accessible to OCaml hackers.

I'd like to thank @rustykey, @mnxn, @prometheansacrifice, and @imbsky
for their contributions to this release. Their help is the reason for
this vastly improved version of the plugin.

As usual, the plugin is available directly using vscode's extension
market place. I'll leave a link to the plugin [here] to avoid
confusion with the many other OCaml plugins available.

Please report any issues on the [bug tracker]

[here]
https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform

[bug tracker] https://github.com/ocamllabs/vscode-ocaml-platform/issues

Other OCaml News
════════════════

From the ocamlcore planet blog
──────────────────────────────

Here are links from many OCaml blogs aggregated at [OCaml Planet].

• [Ocsigen Start 2.18 released]
• [Ocsigen Toolkit 2.7 with new widget Ot_tongue]

[OCaml Planet] http://ocaml.org/community/planet/

[Ocsigen Start 2.18 released]
https://ocsigen.github.io/blog/2020/05/05/os/

[Ocsigen Toolkit 2.7 with new widget Ot_tongue]
https://ocsigen.github.io/blog/2020/05/04/ot/

Old CWN
═══════

If you happen to miss a CWN, you can [send me a message] and I'll mail
it to you, or go take a look at [the archive] or the [RSS feed of the
archives].

If you also wish to receive it every week by mail, you may subscribe
[online].

[Alan Schmitt]

[send me a message] mailto:alan.schmitt@polytechnique.org

[the archive] http://alan.petitepomme.net/cwn/

[RSS feed of the archives] http://alan.petitepomme.net/cwn/cwn.rss

[online] http://lists.idyll.org/listinfo/caml-news-weekly/

[Alan Schmitt] http://alan.petitepomme.net/

[-- Attachment #2: Type: text/html, Size: 33105 bytes --]