Assume I have encoded the natural numbers in Haskell types, and that I have a way of adding and subtracting from them:
data Zero
data Succ n
-- ...
I have seen various bits of code which create the appearance of variadic functions, such as this, which allows the following:
buildList "polyvariadic" "function" "wut?" :: [String]
-- ["polyvariadic","function","wut?"]
What I am wondering is whether I can build off of that to make a function which will only accept the number of arguments that corresponds to an instance of a type number. What I'm trying to do would look something like:
one = Succ Zero
two = Succ one
three = Succ two
threeStrings :: String -> String -> String -> [String]
threeStrings = buildList three
threeStrings "asdf" "asdf" "asdf"
-- => ["asdf","asdf","asdf"]
threeStrings "asdf"
-- type checker is all HOLY CHRIST TYPE ERROR
threeStrings "asdf" "asdf" "asdf" "asdf"
-- type checker is all SWEET JESUS WHAT YOU ARE DOING
I'm aware that this is pretty silly and that it's probably a waste of my time, but it seemed like something that would be fun for the weekend.