In the motivation, the author identifies the 2 big problems with functional programming languages: they use positional arguments (instead of labeled arguments), and they don’t support infix function calls, which means they are not IDE or Intellisense friendly.
To clarify the second point: In OOP languages, you can write object.method(argument)
. The ‘method’ is written in infix position, between the object, which is like the first argument, and the remaining arguments. If you just type object.
, then Intellisense can suggest method names that make sense for the object.
I don’t know why the author thinks that functional programming languages are missing labeled arguments and infix function calls, and that a new language needs to be invented to fill this hole.
The usual trick for using labeled arguments in a function call is to pass a record as an argument. For example, in Curv, you write rotate {angle: 45*deg, axis: Z_axis} cube
to rotate a cube by 45°. The expression {angle: 45*deg, axis: Z_axis}
is a record literal. Modern functional languages have record literals.
The usual trick for writing infix function calls is to use the “pipe forward” operator, which is >>
in Curv, |>
in Elm, F# and many other functional languages. In Curv, you can rotate that cube by writing
cube >> rotate {angle: 45*deg, axis: Z_axis}
Modern functional languages have a pipe-forward operator. Haskell has another syntax for infixing a function call:
a `f` b
is equivalent to f a b
. But I haven’t seen that syntax widely copied in other languages.
In addition to what you said, OCaml supports named parameters similar to Python: is_prefix
has type affix:string -> string -> bool
and is called is_prefix ~affix:"foo" "foobar"
. From a real world library.
merlin supports completion similar to intellisense based on types. If a function expects a t
, it’ll suggest functions that produce t
([1]). After a pipe, it’ll suggest functions that accept a parameter matching the input of the pipe ([2]).
it’s be nice, for pdf papers, to add a bit of context to help people decide whether to read or not.
Good idea.
From the abstract: “This is the year 2008 and ML-style exceptions are everywhere. Most modern languages, whether academic or industrial, feature some variant of this mechanism. Languages such as Java even feature static coverage-checking for such exceptions, something not available for ML languages, at least not without resorting to external tools. In this document, we demonstrate a design principle and a tiny library for managing errors in a functional manner, with static coverage-checking, automatically-inferred, structurally typed and hierarchical exceptional cases, with a reasonable run-time penalty. Our work is based on OCaml and features monads, polymorphic variants, compile-time code rewriting and trace elements of black magic.”
In PureScript or OCaml, you can use open variant types to do this flawlessly
Yes!! Polymorphic variants are incredible
Related paper: https://lobste.rs/s/9akqxf/catch_me_if_you_can
Oh good to know! Is open variant then the ability to define new exceptions, all of which are part of the exn variant?
In fact, you can consider exceptions of exn
to be a special case of the open, or extensible variant! See https://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec266 for more details.
Another thing I thought was nice to mention: row polymorphism.
In row polymorphism, variants are open by default. I’ve been toying with writing my own implementation but this one has a nice readme explaining pretty well how it works.
https://github.com/willtim/Expresso#variants
The reason given for variant literals being open by default is usually to do error handling and only expose our current problems.
Polymorphic variants in OCaml work by row polymorphism - this paper introduced the algorithm and resulted in the ocaml implementation. Good luck with the implementation! It’s my favorite type system feature :)
The usual stuff: awesome with lots of tabs, some poorly written widgets, and a relatively minimal vim with the excellent merlin. xterm for minimal typing latency. Other stuff in the background: cmus, unbound, redshift, neomutt. The laptop is a heavyweight (5 kg) Clevo P775 with desktop components and a 3k screen.
I’ve never seen that one image in the Game of Life article. That looked wild. Do you have a link to that implementation and its parameters so we can replicate it?
Looks like this gun: http://www.conwaylife.com/w/index.php?title=P416_60P5H2V0_gun
Rendered: https://copy.sh/life/?pattern=p41660p5h2v0gun
And if you have some time to waste: http://www.conwaylife.com/wiki/Category:Patterns_with_1000_or_more_cells
I saw some experimentation back when I looked at it with gliders or simple patterns. I didnt know they’d taken it this far with these complex designs. Pretty amazing. Thanks for the link.
Fun facts:
INC esp
(increment stack pointer by one).POP [ptr]
(pop a dword from the stack and move it to the specified address in memory) updates esp
before resolving ptr
(which can contain esp
). In some sense it mixes decoding of the instruction and execution.LEA reg, [ptr]
is an instruction that computes ptr
and stores it in a register without referencing memory. Pointer arithmetic is very flexible in x86, being able to add a register with a shift, another register and a constant offset. For example, it can encode a = b + c -1
in a single instruction. LEA
is also the only instruction that fails when encoded with a register operand (because LEA reg1, reg2
is invalid) but never fails when encoded with a memory operand.OP reg1, reg2
for most instructions.XCHG eax, r
is encoded as 0x90+r
, NOP
is 0x90
or XCHG eax, eax
.NOP
hasn’t been XCHG EAX,EAX
since the 80386—it causes an unnecessary dependency on EAX
so it’s been special coded for quite a long time.
What are you missing about v86? What you want could probably be done if you bring your own assembler (for example by porting NASM using emscripten) and we export some internal apis from v86.
I was hoping for an interface where I can see the registers, flags, memory, etc. in real time along with the .text history, similar to this.
Works out of the box in v86: Get https://www.fiwix.org/FiwixOS-3.2-i386.raw.gz, unpack it locally, go to https://copy.sh/v86/, select FiwixOS-3.2-i386.raw as hard drive image, click start and enjoy :-)
I’ll try to publish https://copy.sh/v86/?profile=fiwix in a couple of hours.
(of course, if you have qemu,
qemu-system-x86_64 -m 128 -enable-kvm FiwixOS-3.2-i386.raw
also works)