{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreieqcapewddlw4ih2axcegd4xnc6xsersmzv4f73yjvewdef6nn6ly",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mhkbethp5hc2"
  },
  "path": "/t/sneak-peek-bolt-math/13766?page=2#post_29",
  "publishedAt": "2026-03-21T04:40:02.000Z",
  "site": "https://discourse.haskell.org",
  "textContent": "One other thing to note: Since Function has a fundep, I think that the associated type family return could be written as\n\n\n    class Function r {- arity ? -} args | r -> {- arity ? -} args where\n        type Return r :: Type\n\n\nI think this is a bit simpler and makes less typing (keystrokes, not types) needed\nAbout variadic functions:\n\nApothecaLabs:\n\n> I didn’t want to rule out support for variadic functions! I haven’t written code to demonstrate handling them, but it should be fairly trivial - you repeat the last argument type indefinitely until the arity runs out, and viola, variadic functions\n\nThis is my effect on making a variadic function like what you describe.\n\n\n    type Repeat :: Nat -> k -> [k]\n    type family Repeat n a where\n        Repeat 0 _ = []\n        Repeat n a = a : Repeat (n-1) a\n    type family Call' (args :: [Type]) out :: Type where\n        Call' '[] out = out\n        Call' (a ': args) out = a -> Call' args out\n\n    type Call :: Nat -> [Type] -> Type -> Type\n    type family Call arity args out where\n        Call 0 '[a] out = TypeError ('Text \"Arity can't be less than list of arguments\")\n        Call n '[a] out = Call' (Replicate n a)\n        Call 0 '[]   out = out\n        Call _ '[]   out = TypeError ('Text \"Arity can't be less than list of arguments\")\n        Call n (a ': args) out = a -> Call (n-1) args out\n\n\nI think the current implementation would be something like this\n\n\n    -- Hypothetical example, not realistic\n    data SubtractOrAddn n\n    instance Function (SubtractOrAddn n) n '[Bool,Int] where\n        type Return (SubtractOrAddn n) = Int -- Assumes Return only takes in the r\n        call :: Call n '[Bool,Int] (Return SubtractOrAdd4)\n        call True = manyfoldl' (n - 1) (+) 0 -- This requires a surprising amount of type hackery to do, as well as knowledge of CPS.\n    -- We also assume RequiredTypeArguments was used to define manyfoldl'\n        call False a = manyfoldl' (n - 2) subtract a\n\n    -- One reason not to like is that we don't actually take in an '[Bool,Int].\n    -- Another is that one might think that\n    -- > call @(SubtractOrAddn 2) takes in 2 ints, but it only takes in 1.\n    -- This isn't apparent from the definition (imo)\n\n\nThis could be done instead:\n\n\n    instance (x ~ Bool ': Repeat (n-1) Int) => Function (SubtractOrAddn n) n x where\n        type Return (SubtractOrAddn n) = Int\n        call = -- Same thing,\n\n\nThis has the advantage of no special casing of Varidic functions in the class, and still allows users to make variadic functions, with no loss of generality! It’s also very clear in the implementation that the `Int` is repeated `n-1` times.\nAlso, variadic functions require a large amount of type level shenanigans to even implement, so I’d be very surprised if many users decide to implement them. If you want, I can share my code for creating them. e.g. stuff like mayfoldl’. It took me a while to make so I’d be more than willing to share it with anyone (assuming I’d be referenced in the package).",
  "title": "Sneak Peek: Bolt Math"
}