Skip to content

Instantly share code, notes, and snippets.

View sneakers-the-rat's full-sized avatar

Jonny Saunders sneakers-the-rat

View GitHub Profile
@hirrolot
hirrolot / printf.idr
Last active November 17, 2024 15:58
Generic `printf` implementation in Idris2
data Fmt = FArg Fmt | FChar Char Fmt | FEnd
toFmt : (fmt : List Char) -> Fmt
toFmt ('*' :: xs) = FArg (toFmt xs)
toFmt ( x :: xs) = FChar x (toFmt xs)
toFmt [] = FEnd
PrintfType : (fmt : Fmt) -> Type
PrintfType (FArg fmt) = ({ty : Type} -> Show ty => (obj : ty) -> PrintfType fmt)
PrintfType (FChar _ fmt) = PrintfType fmt