Abstract

This module contains picklers for primitive Futhark values, as well as combinators for creating array- and tuple-picklers. It can be used directly, or as a building block for application-specific picklers. Trying to unpickle an invalid byte sequence may crash the program.

Synopsis

module type pickle = {
type^ pu 'a
type bytes [n] = [n]u8
val pickle 'a: pu a -> a -> bytes
val unpickle 'a [n]: pu a -> bytes n -> a
val i8: pu i8
val i16: pu i16
val i32: pu i32
val i64: pu i64
val u8: pu u8
val u16: pu u16
val u32: pu u32
val u64: pu u64
val f32: pu f32
val f64: pu f64
val bool: pu bool
val pair 'a 'b: pu a -> pu b -> pu (a, b)
val array 'a: (k: i64) -> pu a -> pu [k]a
val iso 'a 'b: (a -> b) -> (b -> a) -> pu a -> pu b
}
module pickle: pickle

Description

module type pickle
type^ pu 'a

A pickler that describes both how to pickle and unpickle a value of type a.

type bytes [n] = [n]u8

A sequence of bytes.

val pickle 'a: pu a -> a -> bytes

Convert a value to a byte sequence.

val unpickle 'a [n]: pu a -> bytes n -> a

Recover a value from a byte sequence.

val i8: pu i8
val i16: pu i16
val i32: pu i32
val i64: pu i64
val u8: pu u8
val u16: pu u16
val u32: pu u32
val u64: pu u64
val f32: pu f32
val f64: pu f64
val bool: pu bool
val pair 'a 'b: pu a -> pu b -> pu (a, b)
val array 'a: (k: i64) -> pu a -> pu [k]a
val iso 'a 'b: (a -> b) -> (b -> a) -> pu a -> pu b

Given an isomorphism between types a and b, as well as a pickler for a, produce a pickler for b. This is particularly handy for pickling records, as you can simply describe how they can be converted into nested pairs and back again, and then use the pair combinator.

module pickle