Type-Level Programming Example

you can have a function that accepts only prime number of arguments, that are all strings, but occurences of integers at the indixes that are fibonacci numbers

Type-level programming is something that interests me but so far I have only done it in C++. So, here it is in C++, what does it look like in Haskell?

Okay, good question. What does that look like in Haskell? The following code is not pretty. It also gives truly awful error messages. This isn’t a practical technique; it’s just exploring the capabilities of the language for fun.

Edit: Here’s a working version, using techniques demonstrated by jputnam on the Reddit thread. The original code follows.

Original post: It turns out I got most of the way there. Specifically, I am able to declare a function which:

Accepts only a prime number of arguments.

Accepts integers at argument positions that are fibonacci numbers.

Accepts string or integers at positions that are not fibonacci numbers.

It’s certain that there is some way to accomplish that, because the type system is, after all, Turing complete. However, I’m unable to figure it out at the moment. Perhaps someone else can step in and help.