I talk about how to define functions with a variable number of arguments. I am a bit ambitious and wanted to write a mapN function that maps the argument function (n : Nat) to n values ββfor some Applicative type.
Investigating this problem made me think that this is probably not possible, at least also by providing function argument types. This made me try to write a function that takes Nat and a variable number of Type arguments and returns the type of the function, as if you were drawing arrows between types. How in:
Arrows 0 Int = Int Arrows 1 Int String = Int -> String
Here is my best attempt that doesn't work:
Arrows : (n : Nat) -> (a : Type) -> Type Arrows Z a = a Arrows (S k) a = f where f : Type -> Type fb = Arrows ka -> b
Unfortunately, none of the type signatures makes sense, because sometimes I want the function to return Type , and sometimes it returns Type -> Type , and sometimes it returns Type -> Type -> Type and so on. I thought it would be about as simple as writing any other function with a variable number of arguments, but it seems that since these arguments are types, this may not be possible.
Looking back at the answer, I met Kind Polymorphism , which was included by -PolyKinds in Haskell, which seems to allow what is needed here. Am I right in thinking that this is what Idris is missing to make this possible? Or is there another way to do this in Idris?
source share