Threads for copy

  1. 1

    Works out of the box in v86: Get, unpack it locally, go to, select FiwixOS-3.2-i386.raw as hard drive image, click start and enjoy :-)

    I’ll try to publish 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)

    1. 6

      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.

      1. 1

        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]).

        1. 1

          Thanks for the link to Curv, it looks interesting!

        1. 3

          it’s be nice, for pdf papers, to add a bit of context to help people decide whether to read or not.

          1. 4

            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.”

          1. 7

            In PureScript or OCaml, you can use open variant types to do this flawlessly

            Yes!! Polymorphic variants are incredible

              1. 4

                Note that open variants are different from polymorphic variants, albeit both are incredible.

                1. 1

                  Oh good to know! Is open variant then the ability to define new exceptions, all of which are part of the exn variant?

                  1. 4

                    In fact, you can consider exceptions of exn to be a special case of the open, or extensible variant! See for more details.

                    1. 2

                      That’s awesome!

                2. 2

                  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.


                  The reason given for variant literals being open by default is usually to do error handling and only expose our current problems.

                  1. 4

                    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 :)

                1. 3

                  desktop and battle station

                  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.

                  1. 1

                    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?

                      1. 1

                        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.

                    1. 5

                      Fun facts:

                      • All instructions use modrm encoding for encoding memory operands, except for A0/A1/A2/A3, where the address is a constant encoded immediately after the instruction (“moffs”).
                      • x86 has a single-byte encoding for INC esp (increment stack pointer by one).
                      • x86 has a single-byte encoding for BCD-arithmetic. For example: AAA - ASCII Adjust After Addition.
                      • 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.
                      • There are two ways to encode OP reg1, reg2 for most instructions.
                      • XCHG eax, r is encoded as 0x90+r, NOP is 0x90 or XCHG eax, eax.
                      • Most arithmetic instructions also compute the parity flag, which is the parity of the lowest byte of the result.
                      • Most arithmetic instructions also compute the adjust flag, which is set when an overflow happens from the 4th bit of the result.
                      • Due to a bug in Windows NT, CPUID reports some bits differently depending configuration registers. Search for “bug” in
                      1. 2

                        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.

                      1. 1

                        Nice work! I’ve been looking for a x86 virtual machine that is similar to SPIM where I can either enter code line by line or via a file. The v86 project has caught my eye but it’s not quite what I want. Any suggestions?

                        1. 1

                          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.

                          1. 1

                            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.