Skip to content

Instantly share code, notes, and snippets.

@dmjio
dmjio / miso-walkthrough.md
Last active October 15, 2026 06:48
The miso tool, from scratch: a library, a web app, a command line app, and tests

🔋 The miso tool, from scratch: a library, a web app, a command line app, and tests

A walk through the miso command line tool: one binary with MicroHs (0.16.10) and MicroCabal inside, and miso 1.14 already installed. We make a project called todo with:

  • a library (src/Todo.hs): the todo list itself, with no UI;
  • a web app (app/Main.hs, target: browser): miso, WebAssembly;
  • a command line app (cli/Cli.hs, target: native);
  • a test suite (test/Spec.hs).
@dmjio
dmjio / pr-text-nul.md
Last active October 14, 2026 09:09
Draft PR: Data.Text.Encoding NUL fix (MicroHs)

encodeUtf8 returned Text's internal bytes unchanged, so text containing a NUL came out as invalid UTF-8, and decodeUtf8 couldn't read it back.

The problem

Text stores modified UTF-8: NUL is the two bytes C0 80, so a Text never has a 0 byte, which the runtime's C strings need. That's fine internally, but encodeUtf8 returned those bytes as they are, and standard UTF-8 forbids C0 80 (an overlong encoding). So:

>>> B.unpack (encodeUtf8 (pack "a\0b"))
[97,192,128,98]                                   -- not UTF-8
>>> decodeUtf8 (encodeUtf8 (pack "a\0b"))
@dmjio
dmjio / index.ts
Last active August 30, 2025 13:52
initBackground();
globalThis['renderPage'] = function () {
console.log('in main');
console.log('getting global emitter in main should fail', 'getJSModule' in lynx);
const context = lynx.getJSContext();
console.log('js context', context);
// dmj: this works
context.addEventListener("message", (event) => {
@dmjio
dmjio / index.html
Created August 19, 2025 17:37
Web RTC example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebSocket API Example</title>
<style>
* {
margin: 0;
padding: 0;
@dmjio
dmjio / TailwindUI.Components.hs
Created April 5, 2025 20:42
Miso integration with the TailwindUI Components Library, thanks to DeepSeek R1
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
module TailwindUI.Components where
import Miso
import Miso.String (MisoString, ms)
import qualified Data.Map as Map
-- ========================
@dmjio
dmjio / TailwindDaisyMiso.hs
Last active April 5, 2025 19:57
Tailwind Components DaisyUI Library and Miso integration, thanks to DeepSeek R1
{-# LANGUAGE OverloadedStrings #-}
module DaisyUI where
import Miso
import Miso.String (MisoString, ms)
-- Action type for all component interactions
data Action
= ButtonClicked MisoString
| AccordionToggled Int
Build failed.
error: builder for '/nix/store/4nb133jpb8np159fs5c63gjn35h5pl0k-wasm32-unknown-wasi-ghc-native-bignum-9.6.5.drv' failed with exit code 1;
last 10 log lines:
import Data.List (foldl', tails)
import Data.Map.Internal.Debug
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Monoid
import qualified Data.Set as S
data TrieValue v
= TrieValue
{ next :: Trie v
import Data.List (foldl', tails)
import Data.Map.Internal.Debug
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Monoid
import qualified Data.Set as S
data TrieValue v
= TrieValue
{ next :: Trie v
import Data.List (foldl', tails)
import Data.Map.Internal.Debug
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Monoid
import qualified Data.Set as S
data TrieValue v
= TrieValue
{ next :: Trie v