I wish Standard ML had…

I’ve been working with F# since July 2022, and it has been my first true experience with functional programming, as well as with ML-like programming languages. Boy, do I love writing it!

In all fairness, it was just a matter of time before I looked into Standard ML. It turns out that, currently, it’s my favorite programming language. However, things are not that greener on the other side of the fence as I wrote on a previous article: Thoughts on Standard ML as of 2023.

This is just a collection of thoughts I had during my experience writing Standard ML. I might come back here with solutions… or more problems in the future.

Better infix operators

It’s kind of funny that I’m not a big fan of custom operators. Still, having operators such as |> and >> in the standard library really influences how the language ecosystem evolves. You could argue that implementing the pipe operator in Standard ML is as easy as “infix 3 |> fun x |> f = f x” and you would be totally correct! It’s just frustrating that due to a limitation (see MLton’s InfixingOperators) you are required to define the fixity when using it outside its scope definition.

structure Operator = struct
  infix 3 |> fun x |> f = f x

structure Example = struct
  open Operator
  (* I hate doing this :( *)
  infix 3 |>

Polymorphic print function

I know, I know… this might be a bit controversial. You see people asking about this all the time on discuss.ocaml.org: “How do I print X?” or “How do I debug this record?”. In Standard ML, you can’t do that either. Basically, you have to implement your own “toString” function for each type you want to print. Having a basic feature like F#’s printfn "%A" someObj for debugging purposes feels really good in comparison.

One workaround I found to address this issue is to use Poly/ML’s makestring function, which takes any value and returns its string representation. The downside, though, is that you have to use their compiler during development.

Unicode support

That’s it. Standard ML compilers usually provide an extension to allow UTF-8 byte sequences. However, it just doesn’t feel nice to work with it. I would love to have something like Go’s strings and runes!

Computation Expressions

This has more to do with my F# experience. Computation expressions are really powerful, give the documentation a read if you don’t them. It makes “result type-driven” development really easy and much more!

See for yourself one example of the awesome FsToolkit.ErrorHandling library.

type LoginError = InvalidUser | InvalidPwd | Unauthorized of AuthError

let login (username : string) (password : string) : Result<AuthToken, LoginError> =
  result {
    // requireSome unwraps a Some value or gives the specified error if None
    let! user = username |> tryGetUser |> Result.requireSome InvalidUser

    // requireTrue gives the specified error if false
    do! user |> isPwdValid password |> Result.requireTrue InvalidPwd

    // Error value is wrapped/transformed (Unauthorized has signature AuthError -> LoginError)
    do! user |> authorize |> Result.mapError Unauthorized

    return user |> createAuthToken

Articles from blogs I follow around the net

The four tenets of SOA revisited

Twenty years after. In the January 2004 issue of MSDN Magazine you can find an article by Don Box titled A Guide to Developing and Running Connected Systems with Indigo. Buried within the (now dated) discussion of the technology…

via ploeh blog March 4, 2024

Building a demo of the Bleichenbacher RSA attack in Rust

Recently while reading Real-World Cryptography, I got nerd sniped1 by the mention of Bleichenbacher's attack on RSA. This is cool, how does it work? I had to understand, and to understand something, I usually have to build it. Well, friends, that is what…

via ntietz.com blog March 4, 2024

How to unbreak Dolphin on SteamOS after the QT6 update

A recent update to Dolphin made it switch to QT6. This makes it crash with this error or something like it: dolphin-emu: symbol lookup error: dolphin-emu: undefined symbol: _Zls6QDebugRK11QDockWidget, version Qt_6 This is fix…

via Xe Iaso's blog March 3, 2024

Generated by openring