highlights
Jul 28, 2023

🌞 Summer 2023 Unison ecosystem highlights

Rebecca Mark

The Unison ecosystem has been a hive of activity lately! After the launch ofUnison projects,we've seen a number of new libraries materialize. Naturally, we took this as an opportunity to make fun things! Check out the demos and code snippets below. We hope this ecosystem synopsis inspires you to do the same.

Hotswapping Unison code

Inspiration struck Unison contributor@dfreemanin the form of an offhand feature request in Unison's community slack. The nerd-sniping worked and now we have a library for live-updating Unison code as it's running. 🤯 It might have been a speculative idea at the time, but the result isHotswap:a library that enables you to record "placeholder" values in your program and then update them live during the program's runtime.

🔥

A demo is worth a thousand words:

We loved this library so much we created a cloneable project with steps for instrumenting hotswapping so you can try running it yourself!

It's adapted from the excellent video demo in the project's README shown below:

An animated gif demonstrating a hotswap server that responds as it's sent code updates.
Hot-swapping in actionfrom the project's README.

The docs for this library arefantastic🤌 so you can follow along with how the library was implemented, understand the caveats for using hot-swapping, and dream up new use cases.

Json Schema

Thanks to community member@chuwy,Unison has a libray that canmodel,derive,andvalidateJson Schemas. For folks who have never used Json Schemas, they're a way to describe the shape of a Json document andwhew... the schema specification isvast😅!We're very grateful to have@chuwy'sexpertise at work in authoring this library. 📚

Routes

Unison has a new abilities-based library for defining server routes. As you're writing Unison web apps, you can use theRouteslibrary to define how your application should respond if a given route is matched.

Here's what defining routes looks like:

_hiRoute : '{Route} ()
_hiRoute : '{Route} ()
_hiRoute = do
  use Parser /
  use Text ++
  name = route GET (s "hello" / Parser.text)
  ok.text ("👋 hello " ++ name)
_byeRoute : '{Route} ()
_byeRoute = do
  use Parser /
  use Text ++
  name = route GET (s "bye" / Parser.text)
  ok.text ("👋 bye " ++ name)

At the edge of your program, you can combine all of your routes together and serve them on a port.

_main : '{IO, Exception} ()
_main : '{IO, Exception} ()
_main = do
  use Route <|>
  stop = serveSimple (_hiRoute <|> _byeRoute) 8080
  printLine "Server running. Press <enter> to stop."
  _ = readLine
  !stop

Midi Sequencer

Take a look at the ever expanding universe that isAlvaro's project list,and you'll find a new library calledSequencerfor interacting withthe MIDI protocol.Sequencer enables you to write Unison programs for playing music on Midi devices.

You know what that means...

🎹

It's time for a demo! 🎉

If you would like to join the Unison command line band,pull the project hereor write something brand new using theSequencer library.

Terminus

Runar's terminal library is going to radically increase the amount of time you spend playing command line games while your non-Unison code compiles.

Terminus provides a set of functions for interacting with the terminal, including the ability to write text to the screen, read input from the user, and store, move, or reset the cursor at different screen locations.

🐍
The terminus library ships withan example snake game.Just pull the project and enterrun examples.snake.mainin the UCM to start playing.

TLS simple

TLS primitives have existed in Unison's standard lib for a while, but@runaroramarecently added a library that makes it easier to send encrypted messages over a secure channel in Unison. The TLS library is build atop a new TCP server library, also authored by Runar. Rather than managing TCP sockets yourself, you can use more ergonomic functions likeTls.serveandtlsSimple.Tls.connect.

Unison tree-sitter grammar

Tree-sitteris an open-source parsing library that can be used to build syntax highlighting, code folding, and other code editing features. If you've ever wished that your IDE could be "smarter" or more syntactically aware about its suggestions, tree-sitter exists to help languages support those features. Many programming languages publish tree-sitter grammars

Unison's tree-sitter grammar, written by community memberKyle Goetzis animpressivefeat. Unison's grammar is complex and Kyle dove into the Haskell code, combed through our language guide and documentation, and we can only imagine spent many hours working to support all of Unison's unique language features.

We can't wait to incorporate this grammar into our IDE's. Thanks Kyle!

Web Sockets

Unison contributor@danfreemanhas released a library for working with web sockets in Unison. Web sockets enable both the client and server to send and receive information in a two-way data stream. If you've always wondered how web-sockets work, check out thewebsockets.servefunction to see how http requests are upgraded to web-socket connections.

The ecosystem is filling out with fundamental protocol libraries like this one. They're easy to take for granted if you've worked in older languages, so it's nice to be able to see their foundations in Unison.

XML Soup

For your web-scraping needs,@runaroramahas added theSouplibrary for parsing and querying XML documents. It's nestled inside of a larger UnisonXMLlibrary, butSoupis a user friendly interface for traversing through XML so its worth callling out separately.

Fun fact: The Unison blog itself publishes an Atom XML feed: https://www.unison-lang.org/feed.xml. You can use the Soup library to parse and query the feed. Maybe it's time for a Unison RSS reader project? 🤔

_getPosts : Soup ->{Throw XMLError} [(Text, Text)]
_getPosts input =
  use Soup text
  blogXML = input // "feed"
  Each.toList do
    entry = blogXML |> descendants |> Soup.named "entry"
    title = entry // "title" |> text
    date = entry // "updated" |> text
    (title, date)

Plotter library

Unison's tooling for making beautiful charts and graphs is getting off the ground thanks toAlvaro's plotter library.

📈

Now you can move from using this...

A Texas Instruments 83 graphing calculator

To using this...

An image of equations graphed on a 2d plane using the plotter library
Ahhh yes... math 💀

😄 Thank you to our contributors and community

We're constantly wowed by the the ways that folks are using Unison's unique features to build new tools and libraries. Give our library author's a round of applause, or better yet, use their contributions to make something awesome. Happy coding!

An animated gif of running a Unison program that prints the Unison logo to the terminal