25 November, 2016

smuggling things in a dirty bottom

The Haskell unit type, (), has just one value, also written (), right?

smuggle :: Typeable t => t -> ()
discover :: Typeable t => () -> Maybe t

x :: ()
x = smuggle "hello world"

discover x :: Just String
Just "hello world"

These allow you to inject an arbitrary (Typeable) Haskell value into unit and retrieve it later. Just don't try to inspect the resulting () value.

Rather than Haskell 98, you'll need unsafePerformIO and extensible exceptions, put together in a way that lets you hide arbitrary stuff in a thunk, and force evaluation at just the right time.

smuggle :: Typeable t => t -> ()
smuggle v = unsafePerformIO $ throw (toDyn v)

discover :: Typeable t => () -> Maybe t
discover v = either (fromDynamic) (const Nothing)
  $ unsafePerformIO
  $ try
  $ case v of () -> return ()

I could write more. But it's Friday night and I want to drink my wine.

Edit: This is now available on hackage as acme-smuggler.

24 November, 2016


When you're in a cafe

64 bytes from icmp_seq=3 ttl=59 time=26.8 ms
64 bytes from icmp_seq=4 ttl=59 time=23.9 ms
64 bytes from icmp_seq=5 ttl=59 time=26.0 ms

and then their internet dies

From icmp_seq=28 Destination Host Unreachable
From icmp_seq=29 Destination Host Unreachable
From icmp_seq=30 Destination Host Unreachable

and then there is a power cut

From icmp_seq=51 Destination Host Unreachable
From icmp_seq=52 Destination Host Unreachable
From icmp_seq=53 Destination Host Unreachable

but that reset the router

64 bytes from icmp_seq=1786 ttl=59 time=20.7 ms
64 bytes from icmp_seq=1787 ttl=59 time=24.0 ms
64 bytes from icmp_seq=1788 ttl=59 time=21.5 ms

and all is good in the world again.

10 November, 2016

a different technical writing form

My blogger draft box is full of half written posts that I haven't finished - sometimes because I'm lazy; sometimes because the draft is a pile of notes rather than something that could form a coherent post. I've tried embracing that, by dumping a lot of stuff into github at benclifford/text/wiki. This contains a bunch of rambling notes on miscellaneous topics that I have been updating as I think of stuff.